Skip to main content

Regular Expression Functions

Scalar functions for pattern matching and advanced text processing using regular expressions.

regexp_count(string, pattern)

Counts the number of times a regular expression pattern matches in a string.

Parameters

  • string - String expression to search within
  • pattern - String expression representing the regular expression pattern

Description

The regexp_count() function returns the number of non-overlapping matches of the specified regular expression pattern within the input string. If no matches are found, it returns 0. The pattern uses standard regular expression syntax.

regexp_extract_all(string, pattern) / regexp_extract_all(string, pattern, group)

Extracts all matches of a regular expression pattern from a string.

Parameters

  • string - String expression to search within
  • pattern - String expression representing the regular expression pattern
  • group (optional) - Integer specifying which capture group to extract

Description

The regexp_extract_all() function returns an array containing all matches of the specified pattern. When used with two parameters, it returns the entire match. When used with three parameters, it returns the specified capture group from each match.

If no matches are found, it returns an empty array. Capture groups are numbered starting from 1, with 0 representing the entire match.

regexp_extract(string, pattern) / regexp_extract(string, pattern, group)

Extracts the first match of a regular expression pattern from a string.

Parameters

  • string - String expression to search within
  • pattern - String expression representing the regular expression pattern
  • group (optional) - Integer specifying which capture group to extract

Description

The regexp_extract() function returns the first match of the specified pattern. When used with two parameters, it returns the entire match. When used with three parameters, it returns the specified capture group from the first match.

If no match is found, it returns null. Capture groups are numbered starting from 1, with 0 representing the entire match.

regexp_like(string, pattern)

Tests whether a string matches a regular expression pattern.

Parameters

  • string - String expression to test
  • pattern - String expression representing the regular expression pattern

Description

The regexp_like() function returns true if the input string contains a match for the specified regular expression pattern, false otherwise. This function tests for the presence of a match anywhere within the string, not just at the beginning or end.

regexp_position(string, pattern) / regexp_position(string, pattern, start) / regexp_position(string, pattern, start, occurrence)

Returns the position of a regular expression match within a string.

Parameters

  • string - String expression to search within
  • pattern - String expression representing the regular expression pattern
  • start (optional) - Integer specifying the starting position for the search
  • occurrence (optional) - Integer specifying which occurrence to find

Description

The regexp_position() function returns the 1-based position of the first character of a pattern match within the string. When used with the start parameter, it begins searching from that position. When used with the occurrence parameter, it finds the nth occurrence of the pattern.

If no match is found, it returns 0. The start position is 1-based, and the occurrence count begins at 1 for the first match.

regexp_replace(string, pattern) / regexp_replace(string, pattern, replacement)

Replaces matches of a regular expression pattern in a string.

Parameters

  • string - String expression to search within
  • pattern - String expression representing the regular expression pattern
  • replacement (optional) - String expression to replace matches with

Description

The regexp_replace() function replaces all matches of the specified pattern. When used with two parameters, it removes all matches (replaces with empty string). When used with three parameters, it replaces matches with the specified replacement string.

The replacement string can include capture group references using standard regular expression syntax. If no matches are found, the original string is returned unchanged.

regexp_split(string, pattern)

Splits a string using a regular expression pattern as the delimiter.

Parameters

  • string - String expression to split
  • pattern - String expression representing the regular expression pattern to use as delimiter

Description

The regexp_split() function splits the input string at each occurrence of the specified pattern and returns an array of the resulting substrings. The pattern matches are not included in the result array.

If the pattern is not found, the function returns an array containing the original string as a single element. If the pattern matches at the beginning or end of the string, empty strings may be included in the result array.