pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #16826: Regex in substring(... from ..) wrong
2+ messages / 2 participants
[nested] [flat]
* BUG #16826: Regex in substring(... from ..) wrong
@ 2021-01-15 08:23 PG Bug reporting form <noreply@postgresql.org>
2021-01-15 14:20 ` Re: BUG #16826: Regex in substring(... from ..) wrong David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: PG Bug reporting form @ 2021-01-15 08:23 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: james.inform@pharmapp.de
The following bug has been logged on the website:
Bug reference: 16826
Logged by: James Inform
Email address: james.inform@pharmapp.de
PostgreSQL version: 13.1
Operating system: Mac and Ubuntu
Description:
Hopefully I am not messing up regex syntax, but it seems that handling of
non-greedy is not correct in substring function's regex.
When I set the non-greedy operator ? inside a regex in the substring
function, everything after the ? seems to be also treated as non-greedy,
which is wrong.
Please look at the following examples, the last one shows the issue:
select substring('part1.part2.part3' from '^.*');
-- Result: part1.part2.part3
-- Correct, gets the whole string
select substring('part1.part2.part3' from '^.*\.');
-- Result: part1.part2.
-- Correct, because default mode is greedy, so everything until the second
dot is catched
select substring('part1.part2.part3' from '^.*?\.');
-- Result: part1.
-- Correct, because mode is non-greedy, so everything until the first dot is
catched
select substring('part1.part2.part3' from '^.*\..*');
-- Result: part1.part2.part3
-- Correct, everything is catched
select substring('part1.part2.part3' from '^.*?\..*');
-- Result: part1.
-- Wrong, should catch everything but seems to stay non-greedy after the ?
I have also tested against REL_13_STABLE including commit
49c928c0c067a8ec0882eeea5c03ccbd1b1b1a62, but the issue is the same.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #16826: Regex in substring(... from ..) wrong
2021-01-15 08:23 BUG #16826: Regex in substring(... from ..) wrong PG Bug reporting form <noreply@postgresql.org>
@ 2021-01-15 14:20 ` David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: David G. Johnston @ 2021-01-15 14:20 UTC (permalink / raw)
To: james.inform@pharmapp.de <james.inform@pharmapp.de>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
On Friday, January 15, 2021, PG Bug reporting form <noreply@postgresql.org>
wrote:
> The following bug has been logged on the website:
>
> Bug reference: 16826
> Logged by: James Inform
> Email address: james.inform@pharmapp.de
> PostgreSQL version: 13.1
> Operating system: Mac and Ubuntu
> Description:
>
> Hopefully I am not messing up regex syntax, but it seems that handling of
> non-greedy is not correct in substring function's regex.
>
> When I set the non-greedy operator ? inside a regex in the substring
> function, everything after the ? seems to be also treated as non-greedy,
> which is wrong.
>
This seems to behave per the documentation in 9.7.3.5
https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP
Implementations of regex do differ so referencing prior experience for
correctness has limits.
David J.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2021-01-15 14:20 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-01-15 08:23 BUG #16826: Regex in substring(... from ..) wrong PG Bug reporting form <noreply@postgresql.org>
2021-01-15 14:20 ` David G. Johnston <david.g.johnston@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox