Regular Expression with Match activity

Hello, I’m trying to build a regex to get a number from a text, but I can’t figure out what to write, been doing test on Regex101 without any succes.

Here is the text:
No P.O. No com. cli. ASN No. No. référence Mode d’exp Terme d’ach.
111111 23232323 232323 2323232323 COLLECT NET 232323 JOURS

I need to get the ‘111111’ part, all thoses number are faked so I can show you the string here, so have in mind that all those series of number are actual number normally and not just ‘111’ or ‘2323’.

anyone that is more used to regex could help out with a solution? :slight_smile:

but what would be the pattern? you want the first number of that second line?

@MaxyArthes
\d can be used to match a digit 0-9, ^ can be used to match the start of a line.
If the “111111” starts at the beginning of a line you could use ^\d+ to grab “111111”.

^ - start of line
\d - digit
+ - 1 or more of the previous group (digits)

yah, found out a regex that work according to the ‘RegEx Builder’ and Regex101 after, but still no result when trying to get my value in UiPath tho…

(?<=\bréférence Mode d’exp Terme d’ach.\s)(\d+)

so now working to find out what going on

if it is always the first numbers to come up, you can use this:
(^|\s)([0-9]+)($|\s)
and get the second group

my bad, the part I showed is actually a part of a bigger text, that why I start by finding référence Mode d'exp Terme d'ach. and then the next serie of number. It’s just feel like something don’t work in the match activity but I can’t find what character would make it not working.

What I tried so far in regex101 that work and get me no result in UiPath:
(?<=\bréférence Mode d’exp Terme d’ach.\s)(\w+)
(?<=\bréférence Mode d.exp Terme d.ach.\s)(\w+)

@MaxyArthes
How are you configuring the regular expression?
The regex you shared works for me through UiPath

(^|référence Mode d’exp Terme d’ach\.)([0-9]+)($|\s)

yah I know, working for me too in the RegEx Builder, maybe its my logic that don’t work after all,

image

  1. get my pdf into a string (factureText)
  2. does the regex on factureText, store the result in test
  3. for each itemtest in test, show itemtest to screen

nothing pop up on the screen using the message box at point 3

note: I created also a blocnote with the value of factureText to be sure and its the text I was expecting

@MaxyArthes
Make sure that the TypeArgument parameter of your For Each is System.Text.RegularExpressions.Match and then use itemtest.Value instead of itemtest.ToString.

still no result sadly. Copied back the txt file I create just before the ‘Matches’ into the regEx Builder and it’s does match so really, can’t find out what going on. Tried to restart UiPath also.

@MaxyArthes
Can you open the regex configuration and post a screenshot of that here?

edited the private information only but its number for number, so that should not matters

@MaxyArthes
After the Matches activity log test.Count and let me know what the value is.

co-worker passed by and found out the solution x)

(?<=\br.f.rence Mode d.exp Terme d.ach.\s*)(\w+)

it’s needed “\s*” instead of “\s”

2 Likes

This is another regex problem, but thought I could use back my thread to avoid multiple thread about regex.

Total: 1 123.40 $

I’m trying to get ‘1 123.40’, its also must match ‘564.40’ or ‘12 123.40’, depending on how large the number is.

(?<=\bTotal:\s*)(\d )?\d+(,\d{3})*(.\d{1,2})?

^ That where I am now, anyone could help out, with explanation? :slight_smile:

does it always end on " $"?

yes :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.