Task Purpose
The search task takes a regular expression (RegExp) and a string and searches for that RegExp within the string. A RegExp can contain both special and ordinary characters. The task returns an index (number) to indicate the position where a match is found. Indexing starts from zero (0). The task returns -1 if no match is found.
Potential Use Case
The search task checks if a particular string matches for a given regex, or search pattern. You could use this method simply to check if a certain pattern exists and also know its index within a string. In conjunction with the substr method, you could use search to find and replace text in a data record.
Properties
Input and output properties are shown below.
| Input | Type | Description |
|---|---|---|
str |
String | Required. The string (or substring) to search. |
regexp |
String | Required. The search pattern to match in the regular expression. |
| Output | Type | Description |
|---|---|---|
index |
Number | The position where the first match between the regular expression and the given string is found. Returns -1 if not found. Of note, the outgoing index of the first character begins with 0, the second character 1, and so on. |
Example 1
In the example shown below:
- The incoming
strvariable is statically set. The reference variable isHello World. - The search pattern to match in the
regexpvariable isor.

The index result will return 7 upon output, indicating the regexp ("or") is located at index position 7 in the string.

Example 2
In the example shown below:
- The reference variable for the incoming
strisHey Dr. Livingstone. - The search pattern to match in the
regexpvariable is\., which is a special notation (character class) to indicate the match should be a period (".").
For more information, see: Using character classes in regular expressions

The index result returns 6 upon output, indicating the period is located at index position 6 in the string.

Example 3
In this example:
- The incoming
strvariable is statically set. The reference variable isHey Judey. - The
regexpvariable is statically set as\., a character class notation to indicate the match should be a period (".").

The index result returns -1 upon output, indicating a period was not found in the string.
