docs-v2/content/v2.0/reference/flux/functions/regexp/findstringindex.md

1.2 KiB

title description menu weight related
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.
v2_0_ref
name parent
regexp.findStringIndex Regular expressions
301
/v2.0/reference/flux/functions/regexp/compile

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

import "regexp"

regexp.findStringIndex(r: /ab?/, v: "tablet")

// 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
import "regexp"

data
  |> map(fn: (r) => ({
      r with
      regexStr: r.regexStr,
      _value: r._value,
      matchIndex: regexp.findStringIndex(
        r: regexp.compile(r.regexStr),
        v: r._value
      )
    })
  )