Re: Re: Allow Reg Expressions in Position function

From: Geoff Winkless <pgsqladmin(at)geoff(dot)dj>
To: postgresql(at)walla(dot)co(dot)il
Cc: ken(dot)tanzer(at)gmail(dot)com, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Re: Allow Reg Expressions in Position function
Date: 2018-08-20 11:35:23
Message-ID: CAEzk6fdJwwG9aOFBDy-Vkj7OLZwvDriBvLU7Omuw0XEebbdtqw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 20 Aug 2018 at 09:22, Nick Dro <postgresql(at)walla(dot)co(dot)il> wrote:

>
> This incorrect.
> SELECT position(substring('https://www.webexample.com/s/help?' FROM
> '/(s|b|t)/') IN 'https://www.webexample.com/s/help?');
>
> Gives 5. It's wrong.
>

On Mon, 20 Aug 2018 at 09:22, Nick Dro <postgresql(at)walla(dot)co(dot)il> wrote:

>
> This incorrect.
> SELECT position(substring('https://www.webexample.com/s/help?' FROM
> '/(s|b|t)/') IN 'https://www.webexample.com/s/help?');
>
> Gives 5. It's wrong.
>

For some reason, substring() returns the parenthesised subexpression rather
than the top level.

The comment in testregexsubstr does say that it does this, but it's not
clear from the documentation at all, unless I'm missing where it says it.

You can work around this by putting parentheses around the whole
expression, because that way the first subexpression is the whole match.

db=# SELECT position(substring('https://www.webexample.com/s/help?' FROM
'(/(s|b|t)/)') IN 'https://www.webexample.com/s/help?');
position
----------
27

Geoff

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Nick Dro 2018-08-20 13:46:42 RE: Re: Re: Allow Reg Expressions in Position function
Previous Message Nick Dro 2018-08-20 08:22:00 RE: Re: Allow Reg Expressions in Position function