Re: regex help wanted

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: regex help wanted
Дата
Msg-id 24060.1366901995@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: regex help wanted  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Список pgsql-general
Karsten Hilbert <Karsten.Hilbert@gmx.net> writes:
> I would have thought "<[^<]+?:" should mean:

>     match a "<"
>     followed by 1-n characters as long as they are not "<"
>     until the VERY NEXT ":"

> The "?" should make the "+" after "[^<]" non-greedy and thus
> stop at the first occurrence of ":", right ?  Or am I
> misunderstanding that part ?

No, non-greedy just means that if there are multiple ways to make the
pattern match the string, prefer the way that makes this sub-match the
shortest (whereas the default makes leftmost sub-matches longest).
If you don't want the char class to match : then you need to say that
explicitly.

BTW, I'm fairly sure that unless you are doing something that extracts
or replaces sub-matches, there is no value whatever in marking
quantifiers non-greedy; that just complicates life for the regex
compiler.  A match is a match, if you're not paying attention to
where the subpattern boundaries are.

            regards, tom lane


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

Предыдущее
От: Karsten Hilbert
Дата:
Сообщение: Re: regex help wanted
Следующее
От: "Greg Sabino Mullane"
Дата:
Сообщение: Re: session_replication_role `replica` behavior