Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Regular Expression Functions

Regular expression functions: matching, replacing, splitting, and pattern extraction.

Summary

FunctionSignatureDescription
regex_extractstring, string -> arrayExtract regex matches
regex_matchstring, string -> booleanTest if string matches regex
regex_replacestring, string, string -> stringReplace regex matches

Functions

regex_extract

Extract regex matches

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+') -> []

CLI Usage:

echo '{}' | jpx 'regex_extract(`"a1b2"`, `"\\\\d+"`)'

regex_match

Test if string matches regex

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

CLI Usage:

echo '{}' | jpx 'regex_match(`"hello"`, `"^h.*o$"`)'

regex_replace

Replace regex matches

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\"

CLI Usage:

echo '{}' | jpx 'regex_replace(`"a1b2"`, `"\\\\d+"`, `"X"`)'