Re: How best to work around the issue - regex string cannot contain brackets

From: Christophe Pettus <xof(at)thebuild(dot)com>
To: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: How best to work around the issue - regex string cannot contain brackets
Date: 2022-02-03 16:58:45
Message-ID: 7AF5777D-148E-4534-B442-891A911B0D2B@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> On Feb 3, 2022, at 08:53, Shaozhong SHI <shishaozhong(at)gmail(dot)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)

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message David G. Johnston 2022-02-03 17:04:42 Re: How best to work around the issue - regex string cannot contain brackets
Previous Message Shaozhong SHI 2022-02-03 16:53:18 How best to work around the issue - regex string cannot contain brackets