Re: How best to work around the issue - regex string cannot contain brackets
Christophe Pettus <xof@thebuild.com>
From: Christophe Pettus <xof@thebuild.com>
To: Shaozhong SHI <shishaozhong@gmail.com>
Cc: pgsql-sql <pgsql-sql@lists.postgresql.org>
Date: 2022-02-03T16:58:45Z
Lists: 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)