How to do a regex select pattern at last of line?

Good morning friends,

I´m trying to make a regex that selects the 4 digits at the end of the word, I have tried like this: but it does not select the numbers

\d{4}$

5 lines:
SMS VARIOS0103 TN 0403
SMS VARIOS1111 SUP3213 0403
SMS VARIOS SAN2 0403
SMS VARIOS SAN 0403
abc1

You should only select 0403 from each line

regards

can you try: \d{4}\s*?$ maybe some spaces at the end are not recognized

1 Like

it doesn´t select the digits

@Lynx

I can see it’s working for me. Can you try in below Regex site or you can try directly once in UiPath.

1 Like

Hi @Lynx ,
Check below link
\d{4}$

Regards,
Arivu

Hi,

Can you try Mulitiline option, as the following?

Matches activity.

img20220304-7

OR

mc = System.Text.RegularExpressions.Regex.Matches(yourString,"\d{4}$",System.Text.RegularExpressions.RegexOptions.Multiline)

mc is MatchCollection

Regards,

1 Like

I only tried in https://regexr.com/ , in which you recommend me if it works, I will try it in uipath, thank you very much.

I want to capture data like:

SMS VARIOS TN 04.03
SMS VARIOS TN 04_03
SMS VARIOS TN 04-03

with : \d{2}-?.?_?\d{2}\s*?$ , but it doesn´t working in uipath

image

I like use in a variable:

Hi @Lynx ,

Could you try this instead?

image

String.Join(",",System.Text.RegularExpressions.Regex.Matches(str_txtData,"(?<=[^A-z])[\d._\s-]+(?=\r?\n|\s|$)").Cast(Of Match).Select(Function(s) s.ToString.Trim))

Since there are multiple matches, you have to use Matches

MultipleMatches.xaml (5.0 KB)

Kind Regards,
Ashwin A.K

1 Like

The regex will only evaluate line by line, I would like it to capture the last 4 digits in a date (dd-MM). This date can come in 4 types of format ddMM, dd-MM, dd_MM, dd.MM, the date is always the latest.

I tried your regex but it select other numbers more

I also tried this regex before, it works fine on the web, but not on uipath.

In uipath I have it in a variable, but not on uipath:

line= System.Text.RegularExpressions.Regex.Matches(CurrentRow(“Column-1”).ToString,“\d{2}-?.?_?\d{2}\s*?$”)(0).Value

Hi @Lynx ,

Could you try with this pattern instead?

System.Text.RegularExpressions.Regex.Matches(CurrentRow(“Column-1”).ToString,"[\d._-]{4,5}(?=$)")(0).Value

Kind Regards,
Ashwin A.K

1 Like

I tried with below expression and it is coming properly.

(\d{2}[\.\-\_]?\d{2})$

I hope, this helps.

Hi,

FYI, \_ doesn’t work in .net regex. (And - is no need to escape.) So your pattern should be as the following.

\d{2}-?\.?_?\d{2}\s*?$

Or

\d{2}[-._]?\d{2}\s*?$

Regards,

1 Like

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