Regex expression to get string with matches activity

studio
regex

#1

Hi,

I have string

“Dated 12345 Name1 (Name2) Name3 (Name4)”.

My goal is to get “12345”.

I used the regex:
“(?<=” + labelBefore + “)(.*?)(?=” + labelAfter + “)”

As labelBefore I used: “Dated "
As labelAfter I used: " Name1 (Name2) Name3 (Name4)”.

RegexOption: IgnoreCase, Compiled

Result: No match found.

When I try it on regex101.com I runs perfectly, but in UiPath I don’t get a match.

I guess the “(” brackets causing the error. How do I need to change the regex?

Please help
Daniel


#2

Hi @dbcan,

Pattern :(?<=Dated\s).*(?=\sName1\s\(Name2\)\sName3\s\(Name4\))
or
Pattern :(?<=Dated ).*(?= Name1)
or
Pattern :\d{5}
or
Pattern :[0-9]{5}

Regards,
Arivu


#3

@dbcan If its the single occurrence of 5digit, you can directly use \d{5} or [0-9]{5}


#4

For others that come across this, Regex101.com doesn’t show .Net regex computations so it may not work. Use RegexStorm.net.