I want to use Regex to a string to give only 123 from 123123, this could be any number any amount. For example 43564356, 1212, and so on… Sometimes this value is just 1456 then the regex should do nothing, but other times its 14561456 how do i get the 1456 value only?
I have used this website “https://regex101.com/”, its working here but i have problems to convert it to uipath.
Can you try the following expression?
m = System.Text.RegularExpressions.Regex.Match(yourString,"(\d+)(\1)")
Note: m is System.Text.RegularExpressions.Regex.Match.
Thanks, this solves the problem.
But when i have the value only like 1456, theres no output.
What about using just “\d+”, if the above expression returns no match?
Or do you need single regex pattern?
This value is used in a “if” statement, it checks if this value (1456) is equal to another value (1456) im getting from an excel file. So i need a single regex pattern.
Alright. Can you try the following expression?
Still doesn’t match when I have just 1456.
Seems strange. In my environment, it works as the following image.
I found out that, yourString.Groups(0).Value gives the values I want. Either if it is 1456 or 14561456. So the expression is correct.
Thanks then I have the answer that I needed.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.