Re: Match 2 words and more

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Match 2 words and more
Date: 2021-11-28 01:27:26
Message-ID: CAKFQuwYN=1+-2pP2EEWxUcARXgt3OcyYfz_9sEqg1uZmr=PQSg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Nov 27, 2021 at 5:27 PM Shaozhong SHI <shishaozhong(at)gmail(dot)com>
wrote:

> this is supposed to find those to have 2 words and more.
>
> select name FROM a_table where "STREET_NAME" ~ '^[[:alpha:]+
> ]+[:alpha:]+$';
>
> But, it finds only one word as well.
>
> It appears that regex is not robust.
>
> Can anyone shed light on this?
>
>
You put the space inside the first character class (the plus sign within
that class is also a literal plus, not a "one or more" indicator) thus
you've made the space itself optional. Did you maybe mean to use ( )
parens instead of [ ]?

When asking regex questions it is usually more helpful to formulate them
like so:

SELECT 'this should match' ~ '<regex here>';

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron 2021-11-28 02:10:35 Re: Match 2 words and more
Previous Message Guyren Howe 2021-11-28 00:56:25 Re: Match 2 words and more