Search Postgresql Archives

Re: Match 2 words and more

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2021-11-28 00:27:34 +0000, Shaozhong SHI wrote:
> this is supposed to find those to have 2 words and more.
> 
> select name FROM a_table where "STREET_NAME" ~ '^[[:alpha:]+ ]+[:alpha:]+$';

I think you meant

  select name FROM a_table where "STREET_NAME" ~ '^[[:alpha:]+ ]+[[:alpha:]]+$';

Note the extra two brackets.

The character classes (like [:alpha:] or [:digit:] can only be used
within bracket expressions. So you have to put brackets around the
second [[:alpha:], too (like you did for the first one).

But if you look more closely at the first one, you will notice that it
doesn't do what you want, either: It matches any non-empty sequence of
alpabetic characters, plus signs and spaces. But you almost certainly
don't want to match a plus sign, and you don't want space and alphabetic
characters to be interchangable. You want some alphabetic characters
followed by a space. So this becomes

  select name FROM a_table where "STREET_NAME" ~ '^([[:alpha:]]+ )+[[:alpha:]]+$';

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@xxxxxx         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment: signature.asc
Description: PGP signature


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux