// dialect comparison

Regular expression matching: ~, REGEXP and REGEXP_LIKE

Four engines ship regex today, SQL Server only since 2025; SQLite leaves it to the application.

Filed under Querying

The verdict

The function names differ but simple patterns like [0-9]{3} port as written. The flavors split on advanced features: lookahead and lookbehind work in PostgreSQL and MySQL 8.0, not in Oracle or SQL Server 2025, which uses the RE2 library. Don't rely on REGEXP in SQLite, since its behavior depends on whichever function the client registered.

Where they differ

PostgreSQL uses the ~ operator, MySQL the REGEXP keyword, Oracle and SQL Server 2025 the REGEXP_LIKE function. SQLite parses REGEXP but it only works if the application registers a regexp() function. Older SQL Server has only LIKE character classes.

How each engine writes it

SQL Server

SELECT * FROM logs WHERE message LIKE '%[0-9][0-9][0-9]%';

LIKE character classes run on every version. SQL Server 2025 and Azure SQL add REGEXP_LIKE(message, '[0-9]{3}'), which needs database compatibility level 170.

PostgreSQL

SELECT * FROM logs WHERE message ~ '[0-9]{3}';

~ is case-sensitive, ~* case-insensitive, !~ negates. Both [[:digit:]] and \d work.

MySQL

SELECT * FROM logs WHERE message REGEXP '[0-9]{3}';

REGEXP, RLIKE and REGEXP_LIKE() are equivalent. 8.0 uses the ICU library; 5.7 used Henry Spencer's POSIX library.

SQLite

SELECT * FROM logs WHERE message REGEXP '[0-9]{3}';

Parses, then fails with 'no such function: REGEXP' unless the host registers a regexp() function (the sqlite3 shell ships one).

Oracle

SELECT * FROM logs WHERE REGEXP_LIKE(message, '[0-9]{3}');

REGEXP_LIKE, REGEXP_SUBSTR, REGEXP_REPLACE and REGEXP_INSTR since 10g; REGEXP_COUNT since 11g.

Questions that come up

How do I write a case-insensitive regex?

PostgreSQL: ~* or the (?i) prefix. MySQL: REGEXP follows the collation, so it is already case-insensitive on *_ci columns; REGEXP_LIKE(message, 'pattern', 'c') forces case-sensitive and 'i' insensitive. Oracle and SQL Server 2025: REGEXP_LIKE(message, 'pattern', 'i').

Why does the same regex behave differently on MySQL 5.7 and 8.0?

8.0 replaced the Henry Spencer library with ICU. Lookarounds, lazy quantifiers and \d work in 8.0 and not in 5.7, and 8.0 is stricter about invalid patterns. Test patterns against the server version you deploy.

Can an index serve a regex filter?

Usually not. PostgreSQL can turn an anchored pattern such as '^abc' into a B-tree range when the index uses the C collation or text_pattern_ops; other patterns scan. For hot lookups, index a normalized column, or in PostgreSQL use a pg_trgm GIN index, which speeds up both LIKE and regex.

Keep reading

// write it once, run it anywhere

Switch engines without relearning SQL

SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.