Extract
The Extract function extracts the part of the string in the first parameter that matches the regular expression passed in the second parameter and returns it.
Only the parts of the regular expression that are in parentheses are extracted from the string in the first parameter. When more than one part of the regular expression is in parentheses, the strings returned by each part of the expression are concatenated and returned by the function.
Return type
The function return type is: STRING
Function parameters
| Parameter order | Input variable type | Parameter data type | Required parameter | Description |
|---|---|---|---|---|
| 1 | Data field | STRING | Yes | The data field to be searched for the regular expression. |
| 2 | Constant | REGEX | Yes | The regular expression used to find and return part of the string in the first parameter. |
Examples
The following XML shows an example of using the Extract function in an assignment
element.
<assignment field="testExtract" type="Extract" value="ibmNprBdCategory,'([a-z]*)'"/>
In this example, the Extract function is called to return the part of the
ibmNprBdCategory string that matches the regular expression ([a-z]*).
The value returned by the function is assigned to the testExtract field.
The regular expression in the following example extracts only characters 3 - 5 and characters 9 - 10 from a
source string. These two sets of characters are then concatenated and returned by the Extract
function.
^\w{2}(\w{3})\d{3}(\w2)The following table shows examples of the strings that
the Extract function returns for this regular expression.
| Source string | Resulting string | Comments |
|---|---|---|
| ABCDE123XY | CDEXY | |
| ABCDE123XYblahblah | CDEXY | |
| ABCDEFGHXY | No characters were extracted because there were no digits in the source string. The regular expression expects characters 6 - 8 to be digits. |