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

From Shaozhong SHI
Subject Re: How best to work around the issue - regex string cannot contain brackets
Date
Msg-id CA+i5JwZ8BntgpM6J5dsC+66yUMAacQ8DqBr6WsYbo7=0KedccQ@mail.gmail.com
Whole thread Raw
In response to Re: How best to work around the issue - regex string cannot contain brackets  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: How best to work around the issue - regex string cannot contain brackets  (Steve Midgley <science@misuse.org>)
List pgsql-sql
It appears that the following regex work differently.

Why \d and [\d] are different?

[A-PR-UWYZ]\d{1,2} and [A-PR-UWYZ][\d]{1,2}

Regards,

David

On Thu, 3 Feb 2022 at 17:04, David G. Johnston <david.g.johnston@gmail.com> wrote:
On Thu, Feb 3, 2022 at 9:58 AM Christophe Pettus <xof@thebuild.com> wrote:


> 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?

Have you tried reading a book or some tutorials on RegExes?  I'll admit our documentation is probably not the best resource out there to actually learn the language.


You escape the ()s with a backslash:


David J.

pgsql-sql by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: Re: How best to work around the issue - regex string cannot contain brackets
Next
From: Steve Midgley
Date:
Subject: Re: How best to work around the issue - regex string cannot contain brackets