regexp.compile() function

The regexp.compile() function parses a regular expression and, if successful, returns a Regexp object that can be used to match against text.

*Output data type: Regexp*

  1. import "regexp"
  2. regexp.compile(v: "abcd")
  3. // Returns the regexp object `abcd`

Parameters

v

The string value to parse into a regular expression.

*Data type: String*

Examples

Use a string value as a regular expression
  1. import "regexp"
  2. data
  3. |> map(fn: (r) => ({
  4. r with
  5. regexStr: r.regexStr,
  6. _value: r._value,
  7. firstRegexMatch: findString(
  8. r: regexp.compile(v: regexStr),
  9. v: r._value
  10. )
  11. })
  12. )