Extract word using regex

i have string
str = “Text sopp+sopp Ref: 123456 Text”
i want to extract “sopp+sopp Ref: 123456”
i have have this so far
System.Text.RegularExpressions.Regex.Matches(strText,“((sopp+\sopp\s\Ref:\s)\w+)”)
but when i run i get this error

can anyone help?
Thanks

try this instead
(sopp\+sopp\sRef:\s\w+)

if you print
System.Text.RegularExpressions.Regex.Matches(strText,"(sopp\+sopp\sRef:\s\w+)")(0).Value
you should get
sopp+sopp Ref: 123456

That works perfectly.
i dont suppose i could have help with one more?
strText = “Text TSM001-123456 Text”
im trying to extract “TSM001-123456”
i have this so far
System.Text.RegularExpressions.Regex.Matches(strText, “TSM001–\S*”)

Thank you

you can use (TSM001-\S+)

seems like you jsut want to extract the text between "Text " like this
image

if thats the case just use the below regex to handle all your cases, that way you dont need a separate regex for each case
Text\s(.*?)\sText

System.Text.RegularExpressions.Regex.Matches(strText,“(TSM001-\d+)”)(0).Value

sometimes it may not be between ‘text’
it could be between any string

It will only look for what we have given in the expression

1 Like

thank you

1 Like

Your Welcome @Rowley101 and thanks to @jack.chan

My bad this one now is perfect
System.Text.RegularExpressions.Regex.Matches(str,“(TSM001-\d+)”)(0).Value
Happy Automation…!

Regards,
Shaf

what is the difference from the previous one?

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