From: code@phaedrusdeinus.org
To: pgsql-bugs@postgresql.org
Subject: BUG #6381: Incorrect greediness behavior in certain regular expressions
Date: Fri, 06 Jan 2012 00:32:17 +0000
Message-ID: <E1RixjF-0006gP-Dt@wrigleys.postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 6381
Logged by: john melesky
Email address: code@phaedrusdeinus.org
PostgreSQL version: 9.1.1
Operating system: x86_64-pc-linux-gnu
Description:
This simple regexp returns correctly (that is, (.*?) matches
'blahblah.com'):
=# select regexp_matches('http://blahblah.com/asdf';,
'http://(.*?)(/|%2f|$)');
regexp_matches
------------------
{blahblah.com,/}
This, more complex/complete version, matches greedily, which is incorrect:
=# select regexp_matches('http://blahblah.com/asdf';,
'http(s?)(:|%3a)(//|%2f%2f)(.*?)(/|%2f|$)');
regexp_matches
--------------------------------
{"",:,//,blahblah.com/asdf,""}
(That is, (.*?) matches 'blahblah.com/asdf')
The problem appears to be the inclusion of '$' in the final paren group. So,
this works:
select regexp_matches('http://blahblah.com/asdf';,
'http(s?)(:|%3a)(//|%2f%2f)(.*?)(/|%2f)');
regexp_matches
--------------------------
{"",:,//,blahblah.com,/}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: code@phaedrusdeinus.org
Subject: Re: BUG #6381: Incorrect greediness behavior in certain regular expressions
In-Reply-To: <E1RixjF-0006gP-Dt@wrigleys.postgresql.org>
References: <E1RixjF-0006gP-Dt@wrigleys.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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