Skip to content

Regular Expression Functions

Regular-expression matching and transformation functions.

Summary

Function Signature Description
regex_count string, string -> number Count the number of regex matches. Use backtick-JSON syntax: regex_count(text, "\\d+")
regex_extract string, string -> array Extract regex matches. Use backtick-JSON syntax: regex_extract(text, "\\w+")
regex_match string, string -> boolean Test if string matches regex. Use backtick-JSON syntax: regex_match(text, "^\\d+$")
regex_replace string, string, string -> string Replace regex matches. Use backtick-JSON syntax: regex_replace(text, "\\d+", "X")
regex_split string, string -> array Split a string by a regex pattern. Use backtick-JSON syntax: regex_split(text, "\\s+")

Functions

regex_count

Count the number of regex matches. Use backtick-JSON syntax: regex_count(text, "\\d+")

Signature: string, string -> number

Examples:

# Count numbers
regex_count(`"a1b2c3"`, `"\\\\d+"`) -> 3
# Count vowels
regex_count(`"hello world"`, `"[aeiou]"`) -> 3
# No matches
regex_count(`"abc"`, `"\\\\d+"`) -> 0

regex_extract

Extract regex matches. Use backtick-JSON syntax: regex_extract(text, "\\w+")

Signature: string, string -> array

Examples:

# Extract numbers
regex_extract(`"a1b2"`, `"\\\\d+"`) -> [\"1\", \"2\"]
# Extract words
regex_extract(`"hello world"`, `"\\\\w+"`) -> [\"hello\", \"world\"]
# No matches
regex_extract(`"abc"`, `"\\\\d+"`) -> []

regex_match

Test if string matches regex. Use backtick-JSON syntax: regex_match(text, "^\\d+$")

Signature: string, string -> boolean

Examples:

# Full match
regex_match(`"hello"`, `"^h.*o$"`) -> true
# Contains digits
regex_match(`"test123"`, `"\\\\d+"`) -> true
# No match
regex_match(`"abc"`, `"^\\\\d+$"`) -> false

regex_replace

Replace regex matches. Use backtick-JSON syntax: regex_replace(text, "\\d+", "X")

Signature: string, string, string -> string

Examples:

# Replace digits
regex_replace(`"a1b2"`, `"\\\\d+"`, `"X"`) -> \"aXbX\"
# Replace spaces
regex_replace(`"hello world"`, `"\\\\s+"`, `"-"`) -> \"hello-world\"
# No match unchanged
regex_replace(`"abc"`, `"x"`, `"y"`) -> \"abc\"

regex_split

Split a string by a regex pattern. Use backtick-JSON syntax: regex_split(text, "\\s+")

Signature: string, string -> array

Examples:

# Split by comma
regex_split(`"a,b,c"`, `","`) -> [\"a\", \"b\", \"c\"]
# Split by whitespace
regex_split(`"hello   world"`, `"\\\\s+"`) -> [\"hello\", \"world\"]
# No match returns single element
regex_split(`"abc"`, `","`) -> [\"abc\"]