Regex- Need your help

I wanted to extract the below set of data in regex - again my regex pattern works in online regex code builder but not in UiPath - please assist.

(?<=Range\s)([0-9].\d\d%\s\–\s[0-9]+.\d\d%).*\n(\b(?:(?!word)\w)+\b\s)([0-9].\d\d%)

DISCOUNT RATE (IRR)a
Range 6.00% – 10.00% 6.00% – 10.00% 6.00% – 10.00% 7.25% – 12.00%
Average 8.03% 8.03% 8.05% 8.24% 9.08%
Change (Basis Points) 0 – 2 – 21 – 105
OVERALL CAP RATE (OAR)a
Range 4.50% – 7.50% 4.50% – 7.50% 4.50% – 7.50% 4.50% – 7.75%
Average 5.76% 5.79% 5.88% 6.08% 6.45%
Change (Basis Points) – 3 – 12 – 32 – 69
RESIDUAL CAP RATE

required output

6.00% – 10.00% Average 8.03%

@ apurba2samanta - will you be able to assist - Thanks

What online Regex tool are you using?

I use http://regexstorm.net/tester which works with the below pattern (ignore case and multi line selected):
(?<=Range\s)([0-9].\d\d%\s\–\s[0-9]+.\d\d%).*\n(\b(?:(?!word)\w+\b\s)[0-9].\d\d%)

I have removed some grouping to get 6.00% – 10.00% as group 1and Average 8.03% as group 2

1 Like

@TimK,

Am using https://regex101.com/ - I want to implement that same regex code in Uipath

Ok, If you use the matches activity with the following regex

“(?<=Range\s)([0-9].\d\d%\s\–\s[0-9]+.\d\d%).*\n(\b(?:(?!word)\w+\b\s)[0-9].\d\d%)”
Have IgnoreCase,Multiline selected in regex options.
This will give you output of 2 matches of datatable IEnumberable

You can then access each item’s group by doing a for each with Type Argument as Match.
Then add a log of item.Groups(1).ToString + " " + item.Groups(2).ToString

This will give your you required results :smile:

@TimK - not sure what i did wrong am not getting the output -not able to attach my workflow here ,

1 Like

Everything looks correct, what are you setting as argument type in for each?

Also may seem like a silly questions but can you confirm from your read file is outputting to ‘Regex’ variable?

Works for me?

Take a look at your regex options, it might be an issue there:
image

1 Like

@TimK - am using argument type System.text.regularexpressions.match in for each
@CBlanchard - have attached my workflow - please let me where am wrong.Regex_try.xaml (14.9 KB)

consider below as input file

DISCOUNT RATE (IRR)a
Range 6.00% – 10.00% 6.00% – 10.00% 6.00% – 10.00% 7.25% – 12.00%
Average 8.03% 8.03% 8.05% 8.24% 9.08%
Change (Basis Points) 0 – 2 – 21 – 105
OVERALL CAP RATE (OAR)a
Range 4.50% – 7.50% 4.50% – 7.50% 4.50% – 7.50% 4.50% – 7.75%
Average 5.76% 5.79% 5.88% 6.08% 6.45%
Change (Basis Points) – 3 – 12 – 32 – 69
RESIDUAL CAP RATE

1 Like