Hi I have this STRING and want to extract the number that is in front of the “" . Not sure how many "” is in there. So far I have
variable.Split({“_”}, StringSplitOptions.None)
but then what is an efficient way to get all of the 5-digit numbers in front of “_”??
I am not sure if the actual context looks like this but this is what messagebox show me when I print the string named variable
In this case, I need to get 21591, 21593, 21513
I also tried to use claims.Split({“_”},System.StringSplitOptions.None)(1).Trim.Split(Environment.NewLine(0))(0).Trim
but it returns nothing.
And when I use -1 instead of 0 to get previous number, it is out of range…
claims.Split({“_”},System.StringSplitOptions.None)(1).Trim.Split(Environment.NewLine(0))(-1).Trim
@ClaytonM Hi, seems like you are very advanced in string split manipulation, could you please help?
I’m a fan of regex for this use case because it only requires the single step to get your final results. The uipath ‘Matches’ activity can be used for this, which returns an ienumerable value which you can use later in your workflow (generally within a foreach activity).
Here’s an example that works based on the data you provided. It will look for either a carriage return (\r) or newline (\n) before and after 1 or more digits. This would pull out 3 matches of 21591, 21593, 21513 in your example.
(?<=\r|\n)(\d+)(?=\r|\n)
Note that I included both \r and \n as I can’t tell if your data is in newline or carriage return. You should only need to use one or the other
Thank you for your rapid reply! I am very new to regex, could you give a bit more explanation about using that expression? There are more lines that contain 1+ digits in my example above… so I am not sure how this expression can help. For example, the line with 0030 S10120 or 0020… they all have digits in the line… but I only want 21591, 21593, 21513.
(?<=\r|\n) looks for a carriage return or new line immediately preceding any number of digits (\d+). Those digits must also be immediately preceding a carriage return or new line (?=\r|\n)
So it is using these a positive lookahead combined with a positive lookbehind to grab the digits. That is why the expression I gave wouldn’t return anything for the line with 0030 S10120 or 0020. It knows there are digits there, but doesn’t match them because they have whitespace or letters before/after them instead of a new line both before and after.