Hi,
I've got a similar issue with a function that uses regular-expression-magic.
I got it from the sql list and it works but I'm just about 75% aware of how.
Still PG complains about those \\ everywhere.
Replacing every \ by || E'\\' || would make it ... cough ... not
looking cuter as it allready is.
What would be the correct syntax here?
I need it to search phone numbers.
The function strips all characters that are no number or "+" out of the
input-string.
If the international part is "+49" or "0049" it get reduced to 0.
CREATE OR REPLACE FUNCTION cleanphonenr(text)
RETURNS text AS
$BODY$
BEGIN
RETURN CASE
WHEN regexp_replace($1, E'[^0-9+]', '', 'g') ~ E'^(\\+|00)49'
THEN '0'||
regexp_replace(
regexp_replace(
regexp_replace($1, E'[^0-9+()]', '', 'g')
, '\\(0\\)||\\(||\\)', '', 'g')
, E'^(?:\\+|00)49(.*)', E'\\1')
WHEN regexp_replace($1, E'[^0-9+]', '', 'g') ~ E'^(\\+|00)'
THEN '+'||
regexp_replace(
regexp_replace(
regexp_replace($1, E'[^0-9+()]', '', 'g')
, '\\(0\\)||\\(||\\)', '', 'g')
, E'^(?:\\+||00)(.*)', E'\\1')
ELSE
regexp_replace($1, E'[^0-9]', '', 'g')
END;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general