Regex index

Supported in: Batch

Returns an array of indices at which the regular expression pattern is found in the given expression.

Expression categories: Regex, String

Declared arguments

  • Expression - The expression to match against the regular expression.
    Expression<String>
  • Regex - The regular expression to find indices for.
    Expression<String>

Output type: Array<Integer>

Examples

Example 1: Base case

Description: You can find regex patterns and their indices. Argument values:

  • Expression: ababab
  • Regex: ab

Output: [ 0, 2, 4 ]


Example 2: Base case

Description: Overlapping matches are not considered separately; the entire matching segment is treated as a single match. Argument values:

  • Expression: abcdcef
  • Regex: .c.

Output: [ 0 ]


Example 3: Base case

Description: Regex patterns sometimes don't match input strings, resulting in an empty array. Argument values:

  • Expression: abdefg
  • Regex: cd

Output: [ ]


Example 4: Null case

Description: If the expression is null, the output is null. Argument values:

  • Expression: null
  • Regex: ab

Output: null


Example 5: Null case

Description: If the pattern is null, the output is null. Argument values:

  • Expression: ababab
  • Regex: null

Output: null


Example 6: Null case

Argument values:

  • Expression: string
  • Regex: pattern
stringpatternOutput
foofoofoo[ 0, 3 ]
foonullnull
nullabnull
nullnullnull