How to convert - InvokeCode to Find matching patterens

I have an InvokeCode activity which I want to convert into “Find matching patterns” and get red of invokecode activity.
I have never done that before so can someone help me with steps, how to do it.

A simple code is:

pattern = @“(?<=Best Regards)\r?\n\r?\n”;
match = Regex.Match(body, pattern);
if (match.Success) {
hold_UserName = match.Groups[1].Value;
hold_UserJobTitle = match.Groups[2].Value;
} else {
problems.Add(“Syntax Error on User name and job title”);

welcome to the forum

we have the option to unboxing the invoke code black box by translating it to essential activities (VB.Net Syntax)

strText = your Text to check

assign Activity:
strPattern | DataType: String= "(?<=Best Regards)\r?\n\r?\n"

Assign Activity
myMatch | DataType: Match =
System.Text.RegularExpressions.Regex.Match(strText, strPattern )

If Activity | Condition: myMatch.Success

  • indhold_UserNavn = myMatch.Groups(1).Value
  • indhold_UserJobTitle = myMatch.Groups(2).Value
    problems =problems.Append("Syntax Error on User name and job title").ToList

For sure we can also modify / port it to C# etc

How ever keep in mind:

  • the defined regex Pattern is not defining any Groups and it looks not serving the aimed extraction intention
  • do not used variable names same as class names, keywords …

For further help have a look below and feel free to share some samples with us:
[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

Hi @Ellen

You can use the Find Matching pattern activity directly.
In the properties of Find matching pattern activity, In Text to search in pass the Variable which has Input data.
Open the Configure Regular expression, In regex option select the advanced option in the dropdown, In the value give the pattern of regular expression and save.
In the properties there is a result option create a variable in that option, the datatype is IEnumerable of Matches, which stores the extracted data from the Input data.

Check the below image for better understanding

Hope it helps!!


I’m using find matching patterns … but I want to know to use the after

Text: SUB:0521:25697:TestMail:StatusChange

activity : Find matching patterns (have regex of that text)
Result: regexPattern

Assign activity: var_pattren1 = regexPattern(0).group(1).tostring

I did like this… and its giving me only S as a return… where I expected that I should give me a result as SUB

And when I write → var_pattren2 = regexPattern(0).group(2).tostring
It should give me 0521 but not

It only gives me the first letter og each group and I want to know whats i’m doing wrong.
can you help please.

Is there anyone who can tell how to get group value out of regex activity?

Hi @Ellen

=> Drag and drop a “Find Matching Patterns” activity and in the properties panel of the “Matches” activity:

  • Set the “Input” property to your input text.
  • Set the “Pattern” property to your regular expression pattern (including capturing groups).
    => Create a variable to store the MatchCollection result. Let’s name it matches of type System.Text.RegularExpressions.MatchCollection.
    => Use a For Each activity to loop through the matches variable.
    => Inside the For Each loop, use another For Each activity to loop through the groups of each match.
    => Inside the loop, you can access the value of each group using the group.Value property. You can then use this value as needed in your workflow.

Consider this as an Example:
├── Matches (Regex)
│ ├── Input: “Hello 123 and 456”
│ ├── Pattern: “\d+”
│ └── Result: matches (MatchCollection)
└── For Each (item in matches)
├── Sequence
│ └── For Each (group in item.Groups)
│ └── If (group.Name = “0”)
│ └── Log Message: group.Value
└── End For Each

Hope it helps!!



Thanks alot that helps…

can you help with … how can i check the result through if statement… or do i need to do this after match or not?

like I’m trying to check if strTest include (my match)
then divide mymatch groups value into different variable.
otherwise give error.

can you tell how to check that…

we would recommend to check it after myMatch = Regex.Match(…)
therefore we can use the myMatch.Success Property

I can not find the property Success ??


can you help?

ensure that the variable datatype is set to Match

Sample demo:

when using Regex.Match a match is returned

Please also study the above share CheatSheet

You can do learning within the immediate panel as well

I agree that match is returned.
I want to be sure that this match is true and want to put some value from that match into other variables… and if match is not true then I want to send an log message or error message.

that way i needed an IF statement which check is match true or not and that Im unable to do…

we already told:

  • myMatch = regex.Match(…)
  • IF Activity: myMatch.Success
    • Then: var1 = myMatch.Groups(1).Value, var2 = myMatch.Groups(2).Value
    • Else: do the steps, when there was no return

its working now… thanks for the help…
I changed MatchCollection to Match and it worked. my datatype was wrong.
Thanks for the big help…

Perfect, so the topic can be closed by: