// strings reference

SQL REGEXP_LIKE function

Returns true when the string matches the regular expression, false otherwise.

类别
Strings
Returns
boolean
In this category
97 of 172

语法

REGEXP_LIKE(str, pattern [, flags])

引擎支持

引擎Support备注
SQL Server 是 SQL Server 2025 and Azure SQL; a predicate, not a value.
PostgreSQL 是 PostgreSQL 15+; the ~ operator works in every version.
MySQL 是 MySQL 8.0.4 and later.
SQLite Different name or syntax str REGEXP pattern parses, but needs a regexp() function loaded; the sqlite3 shell includes one.
Oracle 是 Supported under this name.

示例

MySQL

SELECT * FROM users
WHERE REGEXP_LIKE(email, '^[a-z0-9.]+@example[.]com$');

Oracle

SELECT * FROM products
WHERE REGEXP_LIKE(sku, '^SKU-[0-9]{4}$');

SQL Server

SELECT * FROM users
WHERE REGEXP_LIKE(email, '@example[.]com$', 'i');

值得了解

  • Oracle and SQL Server treat REGEXP_LIKE as a condition for WHERE, CASE WHEN and CHECK constraints; SQL Server rejects it in a SELECT list, and Oracle allows it there only from 23ai. MySQL returns 1 or 0 and PostgreSQL a boolean.
  • Case defaults differ: MySQL follows the collation, so REGEXP_LIKE('ABC', 'b') is true under the default utf8mb4_0900_ai_ci. Oracle, PostgreSQL and SQL Server match case exactly. Pass 'i' or 'c' instead of relying on the default.
  • The match is not anchored: REGEXP_LIKE('abc', 'b') is true. Anchor with ^ and $ when you mean a full-string match.

Questions about REGEXP_LIKE

Is REGEXP_LIKE the same as LIKE?

No. LIKE uses % and _ wildcards and must match the whole string; REGEXP_LIKE evaluates a regular expression that matches anywhere unless you anchor it.

What is the PostgreSQL equivalent of REGEXP_LIKE?

PostgreSQL 15 added regexp_like(str, pattern [, flags]). The ~ operator does the same in every version: email ~ '^[a-z]+$', with ~* for case-insensitive matching.

How do I make REGEXP_LIKE case-insensitive?

Pass the 'i' flag: REGEXP_LIKE(col, 'pattern', 'i'). It works in MySQL, Oracle, PostgreSQL and SQL Server; 'c' forces case-sensitive matching.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.