Capture groups example
The Match Strings action includes a ‘Capture Groups’ String List parameter that can be used to map substrings from the regular expression matches to columns in the Result dataset. For example, suppose that the Source table for the Match Strings action included the following in its CODE_LINE column.
INCLUDE MV45AOZZ. " User-modules PBO
INCLUDE MV45AIZZ. " User-modules PAI
INCLUDE MV45AFZA. " User-forms < 3.0
INCLUDE MV45AFZB. " User-forms
INCLUDE MV45AFZC. " User-forms < 3.0D
INCLUDE MV45AFZD. " User-forms 3.0E
INCLUDE MV45AFZF. " User-forms 3.0F
If the Match Strings action’s Source Column parameter were set to CODE_LINE, we could extract the name of each INCLUDE into a capture group using the following regular expression in the action’s Patterns parameter:
^INCLUDE\s+(\w+)
In this regular expression:
- ^ anchors the match to the beginning of the string.
- \s+ matches against one or more spaces.
- \w+ matches against one or more letters or digits.
- (\w+) is the capture group containing the name of the INCLUDE.
To include the capture group in the Match Strings action’s Result dataset, add a ‘Capture Groups’ String List parameter to the Match Strings action. The String List parameter should include an entry for each capture group in the regular expression:
INCLUDE_NAME
When the Match Strings action is run for this example, the Result dataset will have an INCLUDE_NAME column which contains the text matched in the (\w+) capture group.
| PATTERN | LINE | MATCH | INCLUDE_NAME | 
|---|---|---|---|
| ^INCLUDE\s+(\w+) | INCLUDE MV45AOZZ. " User-modules PBO | INCLUDE MV45AOZZ | MV45AOZZ | 
| ^INCLUDE\s+(\w+) | INCLUDE MV45AIZZ. " User-modules PAI | INCLUDE MV45AIZZ | MV45AIZZ | 
| ^INCLUDE\s+(\w+) | INCLUDE MV45AFZA. " User-forms < 3.0 | INCLUDE MV45AFZA | MV45AFZA | 
| ^INCLUDE\s+(\w+) | INCLUDE MV45AFZB. " User-forms | INCLUDE MV45AFZB | MV45AFZB | 
| ^INCLUDE\s+(\w+) | INCLUDE MV45AFZC. " User-forms < 3.0D | INCLUDE MV45AFZC | MV45AFZC | 
| ^INCLUDE\s+(\w+) | INCLUDE MV45AFZD. " User-forms 3.0E | INCLUDE MV45AFZD | MV45AFZD | 
| ^INCLUDE\s+(\w+) | INCLUDE MV45AFZF. " User-forms 3.0F | INCLUDE MV45AFZF | MV45AFZF |