Search letter in variable and output whole word

Hi,

I need your help again after a long time :wink:

I read out the variable = “blockStatus”. I always need the complete user ID, i.e. the whole word that starts with “Q” (7 digits) as a new variable.
What should I do ?

blockStatus example:
User Q123456 blocks reservation 00567899999

you can use regex

Regards,

grafik
grafik

@juergenh1975

Use regex

System.Text.RegularExpressions.Regex.Match(blockStatus, “Q\d{7}”).Value

For learning purpose:
[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

@juergenh1975

Use below regex expression

System.Text.RegularExpressions.Regex.Matches(input,"Q\d+")

Hope it works!!

Hi @juergenh1975

Please try this

(?=Q).\d+

Regards,

Hi @juergenh1975

Check the below regular expressions

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“((Q\d{6}))”)

image

If the Q is not fixed and there is more than 6 numbers. Check below one

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“([A-Z]\d+)”)

Hope it helps!!

Hi @juergenh1975

System.Text.RegularExpression.Regex.Matches(Strinput,"(?=[A-Z]).?\d+")
Datatype: System.Collections.Generic.IEnumerable(System.Text.Regular Expression.Match)

Hope it helps!!

Maybe User can also have other Letters on the begin, find a generic approach also handling special chars uppercases

grafik

Hi @juergenh1975
blockStatus=User Q123456 blocks reservation 00567899999

Assign: userID = System.Text.RegularExpressions.Regex.Matches(blockStatus, "Q\d{6}")
or
System.Text.RegularExpressions.Regex.Matches(blockStatus,“([A-Z]\d+)”)

the code works! Thanks !
Many others unfortunately not, but thanks anyway !!!

1 Like

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