Search Postgresql Archives

Re: regexp_matches() quantified-capturing-parentheses oddity

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

 



Julian Mehnle <julian@xxxxxxxxxx> writes:
> So far, so good.  However, can someone please explain the following to me?
>   wisu-dev=# SELECT regexp_matches('quux@foo@bar.zip', '([@.]|[^@.]+)+', 'g');
>   wisu-dev=# SELECT regexp_matches('quux@foo@bar.zip', '([@.]|[^@.]+){1,2}', 'g');
>   wisu-dev=# SELECT regexp_matches('quux@foo@bar.zip', '([@.]|[^@.]+){1,3}', 'g');

These might be a bug, but the behavior doesn't seem to me that it'd be
terribly well defined in any case.  The function should be pulling the
match to the parenthesized subexpression, but here that subexpression
has got multiple matches --- which one would you expect to get?

Instead of (foo)+ I'd try
	((foo+))	if you want all the matches
	(foo)(foo)*	if you want the first one
	(?:foo)*(foo)	if you want the last one

			regards, tom lane

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[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 Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux