Tabular IQ
Back to Function Index

REGEXP_MATCHES()

Overview

REGEXP_MATCHES() returns true when a regular expression matches anywhere in a string, and false when it does not. Use it to filter or flag rows by the shape of a value: invoice numbers that start with a prefix, names that contain a digit, phone numbers that begin with a country code. To test the whole value against a pattern, use REGEXP_FULL_MATCH().

Function Format

REGEXP_MATCHES(string, pattern [, options])

Return Value

REGEXP_MATCHES() returns a boolean value

Examples


// A match anywhere in the string
REGEXP_MATCHES('abc123', '[0-9]+') = true
REGEXP_MATCHES('abc', '[0-9]') = false

// ^ ties the match to the start, $ to the end
REGEXP_MATCHES('abc123', '^[a-z]+') = true
REGEXP_MATCHES('abc123', '^[0-9]+') = false
REGEXP_MATCHES('abc123', '[0-9]+$') = true

// Ignoring case: (?i) in the pattern, or the option 'i'
REGEXP_MATCHES('ABC', '(?i)abc') = true
REGEXP_MATCHES('ABC', 'abc', 'i') = true
REGEXP_MATCHES('ABC', 'abc', 'c') = false

Notes

  • The pattern may match any part of the string. Begin it with ^ and end it with $ to tie it to the start and the end, or use REGEXP_FULL_MATCH().
  • Matching is case-sensitive. (?i) at the start of the pattern ignores case, and so does 'i' as the third argument. The other option letter in everyday use is 's', which lets a dot match a line break.
  • \d, \w and \s stand for a digit, a letter, digit or underscore, and a blank, of the unaccented alphabet. An accented letter counts as one character, but not as a \w.
  • A pattern cannot refer back to one of its own groups or look ahead.
  • A pattern that is not valid is refused, with the reason, when the formula is checked.
  • If the string or the pattern is null, the result is null.
  • The function reads the same on a project table, on a table of a connected database and in a report.

See Also