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

From David G. Johnston
Subject Re: How best to work around the issue - regex string cannot contain brackets
Date
Msg-id CAKFQuwbhQBNQkapttj9KfFTyQkQfvF+wO2EjrkdkY8q_e8MUew@mail.gmail.com
Whole thread Raw
In response to Re: How best to work around the issue - regex string cannot contain brackets  (Steve Midgley <science@misuse.org>)
Responses Re: How best to work around the issue - regex string cannot contain brackets  (Steve Midgley <science@misuse.org>)
List pgsql-sql
On Fri, Feb 4, 2022 at 10:14 AM Steve Midgley <science@misuse.org> wrote:


On Fri, Feb 4, 2022 at 6:01 AM Shaozhong SHI <shishaozhong@gmail.com> wrote:
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}

Show your work!


But when you put characters into brackets, you are telling regex to search for each character represented in the bracket. So [\d] is looking for any single character that is either a \ or a d character. Outside of brackets, regex evaluates \d as any digit.

This is simply wrong.  Test it.

David J.

pgsql-sql by date:

Previous
From: Steve Midgley
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