By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,834 Members | 2,234 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,834 IT Pros & Developers. It's quick & easy.

regex in plpgsql function

P: n/a
I am using 7.4.1

Basically I am trying to use a regex that will match:

john smith
john r smith
john r. smith

When I use:

siteadmin=# select 'john r. smith' ~ '^\\w+\\s+\\w?\\.?\\s?\\w+$';
?column?
----------
t
(1 row)

all is well but:

CREATE OR REPLACE FUNCTION f_tmp(TEXT) RETURNS BOOLEAN AS ' --{{{

BEGIN
RETURN $1 ~ ''^\\w+\\s+\\w?\\.?\\s?\\w+$'';
END;
' language 'plpgsql';

siteadmin=# select f_tmp('john r. smith');
f_tmp
-------
f
(1 row)

makes the same regex seem to behave differently. What am I doing wrong?

culley

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Thu, Jan 22, 2004 at 09:36:14 -0800,
Culley Harrelson <cu****@fastmail.fm> wrote:

makes the same regex seem to behave differently. What am I doing wrong?


I think you have to double the \s again in the function so that there
are 4 \s for each \ in the RE.

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 22 '05 #2

P: n/a
>
I think you have to double the \s again in the function so that there
are 4 \s for each \ in the RE.


Thanks. This worked:

RETURN $1 ~
''^[[:alnum:]_]+[[:space:]]+[[:alnum:]_]?\\.?[[:space:]]?[[:alnum:]_]+$'';
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.