Regexp
The Regexp registry includes functions for pattern matching and string manipulation using regular expressions, providing powerful text processing capabilities.
regexFind / mustRegexFind
The function returns the first match found in the string that corresponds to the specified regular expression pattern.
Signature
Must version
β
{{ regexFind "a(b+)" "aaabbb" }} // Output: "abbb"{{ "hello world" | mustRegexFind "hello" }} // Output: "hello", nil
{{ "hello world" | mustRegexFind "\invalid$^///" }} // Output: "", errorregexFindAll / mustRegexFindAll
The function returns all matches of the regex pattern in the string, up to a specified maximum number of matches (n).
Signature
Must version
β
{{ regexFindAll "a(b+)" "ababab" 2 }} // Output: ["ab", "ab"]{{ mustRegexFindAll "a.", "aba acada afa", 3 }} // Output: ["ab", "ac", "af"], nil
{{ mustRegexFindAll "\invalid$^///", "aba acada afa", 3 }} // Output: "", errorregexMatch / mustRegexMatch
The function checks if the entire string matches the given regular expression pattern.
Signature
Must version
β
{{ regexMatch "^[a-zA-Z]+$" "Hello" }} // Output: true{{ mustRegexMatch "^[a-zA-Z]+$", "Hello" }} // Output: true, nil
{{ mustRegexMatch "\invalid$^///", "Hello" }} // Output: false, errorregexSplit / mustRegexSplit
The function splits the string into substrings based on matches of the regex pattern, performing the split up to n times.
Signature
Must version
β
regexReplaceAll / mustRegexReplaceAll
The function replaces all occurrences of the regex pattern in the string with the specified replacement string.
Signature
Must version
β
regexReplaceAllLiteral / mustRegexReplaceAllLiteral
The function replaces all occurrences of the regex pattern in the string with the specified literal replacement string, without interpreting any special characters in the replacement.
Signature
Must version
β
regexQuoteMeta
The function returns a version of the provided string that can be used as a literal pattern in a regular expression, escaping any special characters.
Signature
Must version
β
Last updated