Re: regular expressions in query

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: regular expressions in query
Дата
Msg-id 22229.1108229240@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: regular expressions in query  ("F.Bissett" <fbissett@blueyonder.co.uk>)
Ответы Re: regular expressions in query  (elein@varlena.com (elein))
Список pgsql-general
"F.Bissett" <fbissett@blueyonder.co.uk> writes:
> </head><BODY BGCOLOR=3D"#F0F0F0" ><p><SPAN style=3D"font-size:10pt;">On Fri=
> , 11 Feb 2005 19:56:33 -0800, Jeff Davis wrote:<br /></SPAN><SPAN style=3D"=
> font-size:10pt;color:navy;">>=A0Try using the "~" regex matching operato=
> r instead of ILIKE.</SPAN><SPAN style=3D"font-size:10pt;"><br /></SPAN><SPA=
> N style=3D"font-size:10pt;color:navy;">></SPAN><SPAN style=3D"font-size:=
> 10pt;"><br /></SPAN><SPAN style=3D"font-size:10pt;color:navy;">>=A0Regar=
> ds,</SPAN><SPAN style=3D"font-size:10pt;"><br /></SPAN><SPAN style=3D"font-=
> size:10pt;color:navy;">>=A0Jeff Davis</SPAN><SPAN style=3D"font-size:10p=
> t;"><br /></SPAN><SPAN style=3D"font-size:10pt;color:navy;">></SPAN></p>

Please don't post HTML email; it's a pain in the neck to quote.

> I have the following PHP to check an input string for non numeric characters:
>
> $tel = ereg_replace('[^[:digit:]]', "", $test); -- tel then equals only the numbers in test.

The closest equivalent we have to that is the regex-extraction version
of the substring() function --- see
http://www.postgresql.org/docs/8.0/static/functions-matching.html
It would go something like

    substring($test from '[0-9]+')

However, what that actually gets you is the first all-numeric substring;
if there are multiple occurrences of digits separated by non-digits this
will not do what you want.

My advice is to write the function you want in one of the PLs that have
good string-mashing facilities --- either plperl or pltcl would
certainly do.  (Probably plpython too, but I'm not very familiar with
Python.)  Plain SQL is not very strong on string manipulation, but
that's why we have extension languages.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Scott Marlowe
Дата:
Сообщение: Re: regular expressions in query
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: is there anyway to get the backends IP address from the