Re: Regex problem

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Regex problem
Дата
Msg-id 12743.1215717734@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Regex problem  ("Scott Marlowe" <scott.marlowe@gmail.com>)
Ответы Re: Regex problem  ("Scott Marlowe" <scott.marlowe@gmail.com>)
Список pgsql-general
"Scott Marlowe" <scott.marlowe@gmail.com> writes:
> ...Which is not surprising.  It's greedy.  So, I turn off the greediness
> of the first + with a ? and then I get this

> select substring (notes from E'LONG DB QUERY.+?time: [0-9]+.[0-9]+')
> from table where id=1;

> LONG DB QUERY (db1, 4.9376289844513): UPDATE force_session SET
> last_used_timestamp = 'now'::timestamp WHERE orgid = 15723 AND
> session_id = 'f5ca5ec95965e8ac99ec9bc31eca84c6New session created
> time: 5.0

> Now, I'm pretty sure that with the [0-9]+.[0-9]+ I should be getting
> 5.03999090194 at the end.

You're getting bit by the fact that the initial non-greedy quantifier
makes the entire regex non-greedy --- see rules in section 9.7.3.5:
http://developer.postgresql.org/pgdocs/postgres/functions-matching.html#POSIX-MATCHING-RULES

If you know that there will always be something after the first time
value, you could do something like

E'(LONG DB QUERY.+?time: [0-9]+\\.[0-9]+)[^0-9]'

to force the issue about how much the second and third quantifiers
match.

            regards, tom lane

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

Предыдущее
От: Devrim GÜNDÜZ
Дата:
Сообщение: Re: apache permission denied
Следующее
От: "Scott Marlowe"
Дата:
Сообщение: Re: Regex problem