Available in versions: Dev (3.16) | Latest (3.15) | 3.14

REGEXP_REPLACE

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The REGEXP_REPLACE() function searches a string for a regular expression pattern, and replaces all or the first occurrence of that string.

Vendors offer different versions of this function, so jOOQ standardises them as two synthetic functions:

  • REGEXP_REPLACE_ALL()
  • REGEXP_REPLACE_FIRST()

For example:

SELECT
  regexp_replace_all('hello', 'l', ''),
  regexp_replace_first('hello', 'l', '');
create.select(
  regexpReplaceAll(val("hello"), "l", ""),
  regexpReplaceFirst(val("hello"), "l", "")).fetch();

The result being

+--------------------+----------------------+
| regexp_replace_all | regexp_replace_first |
+--------------------+----------------------+
| heo                | helo                 |
+--------------------+----------------------+

Dialect support

This example using jOOQ:

regexpReplaceAll(val("hello"), "l", "")

Translates to the following dialect specific expressions:

-- AURORA_MYSQL, DB2, H2, HSQLDB, MARIADB, MYSQL, ORACLE, TERADATA, VERTICA
regexp_replace('hello', 'l', '')

-- AURORA_POSTGRES, COCKROACHDB, MEMSQL, POSTGRES, YUGABYTE
regexp_replace('hello', 'l', '', 'g')

-- HANA
replace_regexpr('l' IN 'hello' WITH '')

-- INFORMIX
regex_replace('hello', 'l', '')

-- ACCESS, ASE, BIGQUERY, DERBY, EXASOL, FIREBIRD, REDSHIFT, SNOWFLAKE, SQLDATAWAREHOUSE, SQLITE, SQLSERVER, SYBASE
/* UNSUPPORTED */

(These are currently generated with jOOQ 3.16, see #10141), or translate your own on our website

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo