Search Postgresql Archives

Re: What's wrong with this regexp?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>>>>> "Nick" == Nick  <nboutelier@xxxxxxxxx> writes:

Nick> SELECT TRUE WHERE '/steps/?step=10' ~ '^\/steps\/\?step=10$'

Here's the first clue:

    merlyn=# select '^\/steps\/\?step=10$';
    WARNING:  nonstandard use of escape in a string literal
    LINE 1: select '^\/steps\/\?step=10$';
                   ^
    HINT:  Use the escape string syntax for escapes, e.g., E'\r\n'.
         ?column?      
    -------------------
     ^/steps/?step=10$
    (1 row)

Notice the \'s just disappeared, so it's not gonna have much good
for the ?, which will be interpreted as the "optional" suffix.

Even adding 'E' (from the hint) isn't quite enough:

    merlyn=# select E'^\/steps\/\?step=10$';
         ?column?      
    -------------------
     ^/steps/?step=10$
    (1 row)

We need the resulting value to have \? in it, and that's not
there yet.  So, that's the clue.  Don't need \/, but do need \\?, so
it looks like this:

    merlyn=# select E'^/steps/\\?step=10$';
          ?column?      
    --------------------
     ^/steps/\?step=10$
    (1 row)

Aha, and now we have the right string for the regex engine, so
let's test that match:

    merlyn=# select '/steps/?step=10' ~ E'^/steps/\\?step=10$';
     ?column? 
    ----------
     t
    (1 row)

Bingo.  True.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@xxxxxxxxxxxxxx> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux