Hello I need help understanding why this doesn’t return what I expected:
Regex.Match("of 850 ",“of (\d+)”)
I expect it to return “850”, but instead it returns “of 850”, isn’t the () supposed to capture the digits only? how can I make this work using Regex, not other methods like split strings. thanks
Essentially your pattern is wrong You are matching ALL of the input string (“of 850”).
The second set of quotation marks (“of (\d+)”) is the ‘Regex pattern’. The brackets just create ‘groups’ within a Regex Pattern. Groups allow you to easily capture components of a bigger string like a year, month and date separately (see below)
Regex Pattern with Groups:
Results with Groups:
If you just need “850” as the result/output then update it to “\d+”. If you want it in group 1 then update the pattern to “(\d+)”.
I would highly recommend using the below template with an Assign activity:
system.Text.RegularExpressions.Regex.Match(INSERTxINPUTxSTRINGxVARIABLE, “INSERTxREGEXxPATTERN”).ToString
Template Explanation:
The italics is where you should place the input string variable.
The bold is where you should insert the Regex Pattern.
my bad, I forgot to use groups(1) to capture the digits, and Match returns the whole matched string including everything. Thank you so much again! I think they should allow multiple solutions here! If you don’t mind I still need to know what each color represents in the attached.
my guess:
Grey: part of all matched string
Yellow: capturing groups