String with certain pattern to values with Regex


#1

I have now tried everything for the whole day now, but can’t get right pattern. I am not experienced with regex, so this is a real pain in the ass.

The pattern I have is:

ClientID:NU74295ClientName:TinyErhartClientCountry:Romania

So the ID, Name and the country are changing, but the categories remain the same. So I want those values after these categories.

I have tried with https://regexr.com/ and https://autohotkey.com/docs/misc/RegEx-QuickRef.htm, but can’t get right answer.

If someone can do it and deliver XAML for an example, I would appriciate it alot.


#2

Hi.

So using the LookBehind (?<=) and LookAhead (?=), you can check for the keyword Client.
Here are 3 patterns to return the text between each item:

"(?<=(ClientID:))(.*)(?=(ClientName))"
"(?<=(ClientName:))(.*)(?=(ClientCountry))"
"(?<=(ClientCountry:))(.*)$"
System.Text.RegularExpression.Regex.Match(text,pattern).Value

There might be better ways, but I hope this helps quickly.

Regards.


#3

Thank you ClaytonM!

I got the first and second one working, but the third (?<=(ClientCountry:))(.*)$ is not working. I tried to fix it by my self but I couldnt do it.

Can you help me with that?

Thanks!!

Edit: Photo of regexr error screen here:

Also tried with [\r\n]+ before the pattern which you delivered.


#4

I’m not sure why your RegExr tool is showing an error, but it works for me in UiPath.
Can you share what isn’t working in UiPath?


image


#5

I was using Matches, the others are working well with Matches. I tried with you method as well, but i got error ‘Regular Expression’ is not a member of ‘text’.

Thanks for helping me!


#6

Make sure you typed it out correctly; it should be “RegularExpressions” like shown in my image.
System.Text.RegularExpressions.Regex.Match().Value
–It should also be listed after you type the period

On your last image where it shows “Object … not set…”
That usually means a variable is empty, so the Matches must not be returning any results. Give my method a shot, because it should work. If not, then the input string might have some other characters that were not considered, and I would need to see your string again to verify.

Thanks.


#7

Thank you.

Got it working with using the Matches. I had to adjust the RegExOption to Multiline, and then it worked.

But thank you very much ClaytonM, this was big help for me!