Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZMUll-0001BO-BS for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Aug 2015 05:28:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZMUlk-0003SF-39 for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Aug 2015 05:28:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZMOU1-0001F3-8B for pgsql-bugs@postgresql.org; Mon, 03 Aug 2015 22:45:25 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZMOTe-0002s3-Qw for pgsql-bugs@postgresql.org; Mon, 03 Aug 2015 22:45:24 +0000 MIME-Version: 1.0 Subject: BUG #13538: REGEX non-greedy is working incorrectly (and also greedy matches fail if non-greedy is present) To: pgsql-bugs@postgresql.org From: christian_maechler@hotmail.com Date: Mon, 03 Aug 2015 22:44:50 +0000 Message-ID: <20150803224450.1115.8803@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.2 (-) Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 13538 Logged by: Chris Mächler Email address: christian_maechler@hotmail.com PostgreSQL version: 9.3.0 Operating system: ? Description: Here is an example to verify and reproduce the error (extract a number and the things before and after it with 3 groups): '(.*)([+-]?[0-9]*\.[0-9]+)(.*)' Using regexü_matches this will produce an undesirable result (only one digit in group 2), but everything behaves correctly, the third group matches until the end. '(.*?)([+-]?[0-9]*\.[0-9]+)(.*)' If we change the first group to non-greedy to fix this, then the bug appears: the third group becomes non-greedy too (it shouldn't!) and therefore it is always empty instead of matching until the end of the line. Also the first group is empty (should match from start!), it should find a match at start position, whether it is non-greedy or not and not look ahead if the non-greedy group can be reduced if starting to match at the next index. Both are wrong behaviors. (the workaround is anchoring, but the behavior of the regex is still wrong) link: http://sqlfiddle.com/#!15/f0f14/14 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs