Using Named Captures in Regexp Patterns

Hello,
is is possible to use Named Captures in a UiPath Match object?
“Change\s(?<named_capture0>(\w)(\d)(\d)(\d)(\d)(\d))”
If so, how you extract <named_capture0>'s value?
Many thanks.

Kindly share some examples for what you are trying to extract from which text

Hi sharazkm32,
Let say I would like to extract the first C… substring from the following string:
“Change C12345 Change C45678”.
I would therefore the following pattern: “Change\s(?<named_capture0>\w\d\d\d\d\d)” or something of the sort.
Normally, the named_capture0 variable should contain “C12345”.

@pr1

Use the Matches Activity:

Set the Pattern property to:

Change\s(?<named_capture0>C\d{5})

Set the RegexOption to None or IgnoreCase (depending on case sensitivity).

The output of the Matches activity is a collection of matches.

Use an Assign activity to get the value of the first match:

firstMatch = matchCollection(0).Groups("named_capture0").Value

Make sure matchCollection is of type IEnumerable<Match> and firstMatch is a String.

Fantastic. Thank you very much ashokkarale.

1 Like

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