Re: How best to work around the issue - regex string cannot contain brackets - Mailing list pgsql-sql

From Christophe Pettus
Subject Re: How best to work around the issue - regex string cannot contain brackets
Date
Msg-id 7AF5777D-148E-4534-B442-891A911B0D2B@thebuild.com
Whole thread Raw
In response to How best to work around the issue - regex string cannot contain brackets  (Shaozhong SHI <shishaozhong@gmail.com>)
Responses Re: How best to work around the issue - regex string cannot contain brackets  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-sql

> On Feb 3, 2022, at 08:53, Shaozhong SHI <shishaozhong@gmail.com> wrote:
>
> One would consider the following would work, but it did not because the brackets.
> select regexp_matches('Department for Transport (Parking)', 'Department for Transport (Parking)', 'g')
>
> Can anyone enlighten me?

You escape the ()s with a backslash:

xof=# select regexp_matches('Department for Transport (Parking)', 'Department for Transport \(Parking\)', 'g');
             regexp_matches
----------------------------------------
 {"Department for Transport (Parking)"}
(1 row)




pgsql-sql by date:

Previous
From: Shaozhong SHI
Date:
Subject: How best to work around the issue - regex string cannot contain brackets
Next
From: "David G. Johnston"
Date:
Subject: Re: How best to work around the issue - regex string cannot contain brackets