Split a string and retrieve multiple strings

This is the string I need to split:
Request # 00518551

Blockquote

"POS# 852-1890-024, 852-1890-001, 852-1890-999"

Blockquote

I need to derive the string in between the p html tags and then get the last 3 digits for each of the enclosed strings…i.e 852-1890-024, 852-1890-001, 852-1890-999
I need to get 024,001 and 999.

Any help is appreciated.
Thanks

@chauhan.rachita30

You can try this using regex declare a list fo strings and initialize it with list(of string) using assign

Now use assign with list of strings variable on left and the below formula on right, output would be the 3 numbers(type is of string) list …

System.Text.RegularExpressions.Regex.Matches(str,"(?<=\d{3}-\d{4}-)\d{3}").Select(function(x) x.Value).ToList()

Hope this helps

Cheers

`

1 Like

Hi - I’m following the UiPath training course and this looked like an interesting ad-hoc exercise. See screenshot below and attached XAML for my solution. I’m sure there are better ways of doing this - would be interested to know what more experienced UiPath developers suggest.

Main.xaml (8.4 KB)

Well, that’s a bit more concise than my attempt! :wink:

1 Like

Hi,

FYI, it’s necessary Cast method as the following.

System.Text.RegularExpressions.Regex.Matches(str,"(?<=\d{3}-\d{4}-)\d{3}").Cast(Of System.Text.RegularExpressions.Match).Select(function(x) x.Value).ToList()

getting a compiler error:

HI,

Did you define variable named str?
Or replace str in the expression with your input string variable.

Regards,

Thank you very much!!!

2 Likes

I forgot that this expression could have 2 or more position numbers like:
POS# 852-1890-024, 852-1890-001
They can be 2 or more than 2.
What will be the regex in that case.

Hi,

The above expression returns List which has “024” and “001”
Isn’t this what you expect? If not, can you share expected result in this case?

Regards,

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