Name

\ (Backslash) — Escapes a metacharacter

Synopsis

Use the backslash (\) to treat as normal a character that would otherwise have a special meaning. For example, to extract a dollar amount from a sentence, you might escape the period (.) and the dollar sign ($) as follows:

SELECT REGEXP_SUBSTR(
   'This book costs $9.95 in the U.S.',
   '\$[[:digit:]]+\.[[:digit:]]+')
FROM dual;

$9.95

The \$ in this expression requires that the matching text begin with a dollar sign. The \. requires a period between the two digit groups.

To specify a backslash in an expression, escape it with another backslash. The following query retrieves all text up to and including the last backslash:

SELECT REGEXP_SUBSTR(
   'I want this \ but not this',
   '.*\\')
FROM dual;

I want this \

If the character following a backslash in an expression is not a metacharacter, then the backslash is ignored:

SELECT REGEXP_SUBSTR('\test','\test')
FROM dual;

test

The \ has no special meaning within square brackets ([]). When used within square brackets, \ represents itself.

Get Oracle Regular Expressions Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.