Re: Match 2 words and more

Поиск
Список
Период
Сортировка
От Peter J. Holzer
Тема Re: Match 2 words and more
Дата
Msg-id 20211128112614.enaoxuu5ph4w3qo6@hjp.at
обсуждение исходный текст
Ответ на Match 2 words and more  (Shaozhong SHI <shishaozhong@gmail.com>)
Список pgsql-general
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@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: "Godfrin, Philippe E"
Дата:
Сообщение: RE: [EXTERNAL] Re: Inserts and bad performance
Следующее
От: "Peter J. Holzer"
Дата:
Сообщение: Re: Match 2 words and more