From: | "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com> |
---|---|
To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | regexp match in plpgsql |
Date: | 2011-02-22 22:55:57 |
Message-ID: | 482E80323A35A54498B8B70FF2B87980048B2374DD@azsmsx504.amr.corp.intel.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
V8.3.4 on linux
How does one do a regexp match/test in PlPgsql given a text variable containing a regexp and another text variable containt the string to test. Example that shows what I'm trying to do...
declare
rgxp text;
str1 text;
str2 text;
begin
rgxp := '[a-zA-Z0-9]';
str1 := 'ShouldBeOK99';
str2 := 'Should_Fail_match77';
if(str1 =~ E\rgxp\) then raise notice '% is a match',str1; else raise notice '% is not a match',str1; end if;
if(str2 =~ E\rgxp\) then raise notice '% is a match',str2; else raise notice '% is not a match',str2; end if;
end;
$$ language plpgsql
I would expect to see...
"ShouldBeOK99 is a match"
"Should_Fail_match77 is not a match"
Thanks in Advance.
From | Date | Subject | |
---|---|---|---|
Next Message | Kevin Grittner | 2011-02-22 23:29:26 | Re: How to extract a value from a record using attnum or attname? |
Previous Message | Andrew Dunstan | 2011-02-22 22:55:23 | Re: Re: [GENERAL] How to extract a value from a record using attnum or attname? |