Re: Escaping parenthesis in regular expressions.... - Mailing list pgsql-general

From Tom Lane
Subject Re: Escaping parenthesis in regular expressions....
Date
Msg-id 14970.963609558@sss.pgh.pa.us
Whole thread Raw
In response to Escaping parenthesis in regular expressions....  ("Steve Wolfe" <steve@iboats.com>)
List pgsql-general
"Steve Wolfe" <steve@iboats.com> writes:
>   How does one escape parenthesis in a regular expression in Postgres?

> select * from subcategories where subcategory ~* '401\(k\)';

> That still didn't work.

You need two backslashes:

select * from subcategories where subcategory ~* '401\\(k\\)';

The first of each pair gets eaten by the parser when the string literal
is parsed, so what arrives at the ~* operator at runtime is
        401\(k\)
which is what you need.

            regards, tom lane

pgsql-general by date:

Previous
From: Charles Tassell
Date:
Subject: Re: Escaping parenthesis in regular expressions....
Next
From: Richard Harvey Chapman
Date:
Subject: Re: psql \i --UPDATE