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

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

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, YUGABYTEDB
regexp_replace('hello', 'l', '', 'g')

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

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

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

(These are currently generated with jOOQ 3.19, 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