X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id BA33F3A41D6 for ; Tue, 23 Nov 2004 23:41:37 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 42428-04 for ; Tue, 23 Nov 2004 23:41:32 +0000 (GMT) Received: from main.gmane.org (main.gmane.org [80.91.229.2]) by svr1.postgresql.org (Postfix) with ESMTP id AE4153A41A5 for ; Tue, 23 Nov 2004 23:41:34 +0000 (GMT) Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1CWkHu-0003pL-00 for ; Wed, 24 Nov 2004 00:41:34 +0100 Received: from 212.209.14.34 ([212.209.14.34]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 24 Nov 2004 00:41:34 +0100 Received: from thhal by 212.209.14.34 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 24 Nov 2004 00:41:34 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-general@postgresql.org From: Thomas Hallgren Subject: Re: Regexp matching: bug or operator error? Date: Wed, 24 Nov 2004 00:41:26 +0100 Lines: 18 Message-ID: <41A3CAA6.7070100@mailblocks.com> References: <41A3C6C6.2090605@desc.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 212.209.14.34 User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) X-Accept-Language: en-us, en In-Reply-To: <41A3C6C6.2090605@desc.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/1142 X-Sequence-Number: 69222 Ken Tanzer wrote: > Using Postgres V. 7.4.1, the following query: > > SELECT substring('X12345X' FROM '.*?([0-9]{1,5}).*?'); > > Returns '1'. I would expect it to return '12345'. Is this a bug, or am > I missing something? Thanks. > The regexp {1,5} is satisfied with the minimum of 1 digit. It looks ahead and finds your '.*'. That in turn consumes all but the last character. Perhaps what you want is '[^0-9]+([0-9]{1,5})[^0-9]+' Translates to "at least one non digit followed by 1-5 digits and then at least 1 non digit". Regards, Thomas Hallgren