Re: substring regular expression

From: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
To: Barry Brunning <barry(dot)brunning(at)datastream(dot)com(dot)au>
Cc: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: substring regular expression
Date: 2013-09-27 23:29:21
Message-ID: CAL_0b1umh5Orph4qNAKH6nCCruzA+_MbwtFVGKtB_yJfzEoC_w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Thu, Sep 26, 2013 at 11:35 PM, Barry Brunning
<barry(dot)brunning(at)datastream(dot)com(dot)au> wrote:
> This works (returns 12345):
> select substring('ABC 12345 XYZ' from '%#"[0-9][0-9][0-9][0-9][0-9]#"%' for '#') as found_5_digits;
>
> While this fails (returns blank):
> select substring('ABC 12345 XYZ' from '%#"[0-9]{5}#"%' for '#') as no_5_digits;
>
> Am I misunderstanding the documentation on using [0-9]{5} or do you think it's a bug?

The "for escape" version of substring() supports SQL regexp syntax
only, that doesn't have {N} construction. The "non for escape" version
supports POSIX regexp syntax, that does have it:

select substring('ABC 12345 XYZ' from ' \d{5} ');

--
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA

http://www.linkedin.com/in/grayhemp
+1 (415) 867-9984, +7 (901) 903-0499, +7 (988) 888-1979
gray(dot)ru(at)gmail(dot)com

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message James David Smith 2013-10-02 10:02:43 Advice on upgrading from PostgreSQL 9.0
Previous Message Barry Brunning 2013-09-27 06:35:46 substring regular expression