Re: What's wrong with this regexp?
От | merlyn@stonehenge.com (Randal L. Schwartz) |
---|---|
Тема | Re: What's wrong with this regexp? |
Дата | |
Msg-id | 86d44uoors.fsf@blue.stonehenge.com обсуждение исходный текст |
Ответ на | What's wrong with this regexp? (Nick <nboutelier@gmail.com>) |
Список | pgsql-general |
>>>>> "Nick" == Nick <nboutelier@gmail.com> 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@stonehenge.com> <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
В списке pgsql-general по дате отправления: