Matches (regex)

Hi, i want extract data in word document. The data is between words
So i use this regex

(?<=(REFERENCE))(\w|\d|\n|[(.*)]| )+?(?=( CAHIER))

When i try it on https://regex101.com, it’s work fine, but on UiPath the result is always null/empty.
How i can resolve this ?

Thank for your reponse
Have a good day

The document is

REFERENCE

000000

CAHIER

1 Like

Hello @Tulifer,

Your regex “(?<=(REFERENCE))(\w|\d|\n|[(.*)]| )+?(?=( CAHIER))” only works on https://regex101.com, with global regex flag:

This regex: “(?<=REFERENCE)[\s\S]*(?=CAHIER)” works in UiPath Studio

Matches.zip (2.6 KB)

Regards,
Susana

4 Likes

This will work too “(?<=REFERENCE)(.*)(?=CAHIER)"

1 Like

@Susana & @palindrome Thanks for your reply, it’s work fine.

Now i try other text like.
So i use the same method

(?<= Liste des questions : )[\s\S]*(?=Liste )

Why doesn’t work when i have : in my sentence ?

Liste des questions :

aaaaaaaaaaaaaaaaaaaaaa

Liste des réponses :

Did you check for spaces? Try to use variables with Trim property which will remove all the leading and trialing spaces.

(?<=Liste des questions :)[\s\S]*(?=Liste)

For those who are not fans of Regex can try this

Line.Split(New String() {"REFERENCE","CAHIER"}, StringSplitOptions.RemoveEmptyEntries)(0)

1 Like

Hi,
I have total of 3 different Regex patterns, is it possible to make a regex engine comprising of all the three patterns?
what i am currently doing is, my pdf text is passing through first pattern, if the count is returning 0, it goes through second pattern and so on.
Is it possible that the pdf text extracted passes through all the 3 patterns at once??

Keep your patterns in Array and use foreach loop with matches activity, keep if condition inside foreach loop to check the condition.

Hi,
Thanks for your reply, i am trying to do as you suggested but i am getting the below error.
image

I have stored all my Patterns in an array RegexPattern and passing the same into matches.

image

image