Looking for help with using regular expression match or perl language functions - Mailing list pgsql-general

From Richard DeVenezia
Subject Looking for help with using regular expression match or perl language functions
Date
Msg-id 059201c03e3e$b76c5ac0$0101a8c0@supermicro
Whole thread Raw
In response to Re: ok after months of freedom I'm suddenly back on the damn list aga in  (The Hermit Hacker <scrappy@hub.org>)
Responses Re: Looking for help with using regular expression match or perl language functions  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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


pgsql-general by date:

Previous
From: Pawel Wegrzyn
Date:
Subject: latest version?
Next
From: Peter Keller
Date:
Subject: Re: Problems with genetic optimizer