From: | "Richard DeVenezia" <radevenz(at)ix(dot)netcom(dot)com> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Looking for help with using regular expression match or perl language functions |
Date: | 2000-10-25 04:47:43 |
Message-ID: | 059201c03e3e$b76c5ac0$0101a8c0@supermicro |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi:
I'm just getting into pgsql, but have lots of sql experience.
I've read what I can find (Momjian and docs/faqs at .org)
Consider this perl regular expression in which $1 records the part of the
text that matches my regexp:
# print first word of string when first word starts with r and ends with d
$text = "Read this Richard";
if ( $text =~ m/(^r\S*d)\b/i ) { print "first word is: '$1' \n" }
Consider this sql to create some sample data:
create table comment (text varchar(200));
insert into comment values ('Richard was here');
insert into comment values ('Read about this');
insert into comment values ('Rodeo is in town');
What would be the pgsql statement to get a regexp match such as $1 into a
column ?
e.g., could it be like ...
select
$1 of m/(^r\S*d)\b/i, text AS part_of_text_that_matches_regexp
from
comments
;
If native pg does not support using regexp matches, I suppose I would want
to write a procedural language function using perl. I've yet to locate
examples of this.
I don't need help with substr and index to grab and test first words, I only
did that to simplify the example. In reality I am using much more
convoluted and complicated regular expressions.
TIA,
Richard DeVenezia
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Keller | 2000-10-25 06:04:36 | Re: Problems with genetic optimizer |
Previous Message | Tom Lane | 2000-10-25 03:59:06 | Re: Delete temp tables |