regexp.findStringIndex() function

The regexp.findStringIndex() function returns a two-element array of integers defining the beginning and ending indexes of the left-most regular expression match in a string.

*Output data type: Array of Integers*

  1. import "regexp"
  2. regexp.findStringIndex(r: /ab?/, v: "tablet")
  3. // Returns [1, 3]

Parameters

r

The regular expression used to search v.

*Data type: Regexp*

v

The string value to search.

*Data type: String*

Examples

Index the bounds of first regular expression match in each row
  1. import "regexp"
  2. data
  3. |> map(fn: (r) => ({
  4. r with
  5. regexStr: r.regexStr,
  6. _value: r._value,
  7. matchIndex: regexp.findStringIndex(
  8. r: regexp.compile(r.regexStr),
  9. v: r._value
  10. )
  11. })
  12. )

Related articles