How can i find the matching values in my string?

i have a str = ‘TSM001 – XXXXXX’

im using
System.Text.RegularExpressions.Regex.Matches(str,“TSM001 - \S*”)

to try and get the value but its not working

is there a way to do this?

Hi @Rowley101,

The Matches will return a group, you can also use Regex.Match instead.

Here is a good forum post for your future reference: Regex help tutorial MEGAPOST – Making your first Regex post, Reusable Regex Patterns, Regex Troubleshooting, Sample Workflow and more - News / Tutorials - UiPath Community Forum

Solution:
System.Text.RegularExpressions.Regex.Match(TestString, "((?<=TSM001\s–\s)\w+)").ToString

GetStringRegexMatch.xaml (4.9 KB)

You are almost done
Try with this expression

(TSM001)\s\W\s\w+

Cheers @Rowley101

Hi @Rowley101 ,

You can try this pattern
(?<=TSM001 \W )(\S+.*)

does the ‘s’ in ((?<=TSM001\s–\s)\w+) symbolize a space?

Hi again @Rowley101,

That is correct.
I use \s to denote a Space character. You can in reality also just use a SPACE or multiple SPACES if your string requires it, but in my opinion \s makes it easier to read regex expressions.

1 Like

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