Re: Escaping parenthesis in regular expressions....

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Steve Wolfe" <steve(at)iboats(dot)com>
Cc: "Pgsql-General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Escaping parenthesis in regular expressions....
Date: 2000-07-14 21:19:18
Message-ID: 14970.963609558@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Steve Wolfe" <steve(at)iboats(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Harvey Chapman 2000-07-14 21:33:07 Re: psql \i --UPDATE
Previous Message Charles Tassell 2000-07-14 18:57:51 Re: Escaping parenthesis in regular expressions....