regular expression question

Started by Parker Thompsonalmost 24 years ago7 messagesgeneral
Jump to latest
#1Parker Thompson
parkert@u.washington.edu

I have a question regarding regular expression with postgres.

I am unable to find any reference to match on word boundaries (\b in
perl). If this functionality exists in postgres I am interested in
knowing how to use it, an example would probably suffice.

If it does not, which is what I suspect, I am interested in knowing how
others have dealt with this problem. It seems silly/ineffecient to just
try all cases, i.e. field ~* (^term| term | term$), but I can't think of a
better way.

Thanks,

Parker.
----------------------------------------------------------------
"Tom would prefer you use Emacs, because it makes Justin really
mad. Justin would prefer you use vi, because he thinks Tom
suffers from some vicious malaise. You'll probably be lame and
end up using Pico."
-Shoutcast Server Documentation

#2Alvaro Herrera
alvherre@atentus.com
In reply to: Parker Thompson (#1)
Re: regular expression question

Parker Thompson dijo:

I have a question regarding regular expression with postgres.

I am unable to find any reference to match on word boundaries (\b in
perl). If this functionality exists in postgres I am interested in
knowing how to use it, an example would probably suffice.

If it does not, which is what I suspect, I am interested in knowing how
others have dealt with this problem. It seems silly/ineffecient to just
try all cases, i.e. field ~* (^term| term | term$), but I can't think of a
better way.

You can use [[:<:]] and [[:>:]] as word boundaries.

--
Alvaro Herrera (<alvherre[a]atentus.com>)
"La vida es para el que se aventura"

#3David Ford
david+cert@blue-labs.org
In reply to: Alvaro Herrera (#2)
Re: regular expression question

I wish everyone would use the same syntax...it's getting to the point
where you need a reference book for everybody's idea of how regex should
be done.

-d

Alvaro Herrera wrote:

Show quoted text

Parker Thompson dijo:

I have a question regarding regular expression with postgres.

I am unable to find any reference to match on word boundaries (\b in
perl). If this functionality exists in postgres I am interested in
knowing how to use it, an example would probably suffice.

If it does not, which is what I suspect, I am interested in knowing how
others have dealt with this problem. It seems silly/ineffecient to just
try all cases, i.e. field ~* (^term| term | term$), but I can't think of a
better way.

You can use [[:<:]] and [[:>:]] as word boundaries.

#4Alvaro Herrera
alvherre@atentus.com
In reply to: David Ford (#3)
Re: regular expression question

David Ford dijo:

I wish everyone would use the same syntax...it's getting to the point
where you need a reference book for everybody's idea of how regex should
be done.

In Linux (well, at least in Mandrake) you can look at regex(7) for the
POSIX 1003.2 standard regexes, plus some things Henry Spencer added. His
implementation is the one used in Postgres internally, so it has some
value.

--
Alvaro Herrera (<alvherre[a]atentus.com>)
"El dia que dejes de cambiar dejaras de vivir"

#5David Ford
david+cert@blue-labs.org
In reply to: Alvaro Herrera (#4)
Re: regular expression question

Yes, and honestly I rather prefer the POSIX syntax in most cases, but I
do like some of the shorthands, i.e. < (or \<) is so much easier to type
than "[[:<:]]", and the same for > v.s. "[[:>:]]". That's just silly.
This by the way is an extension.

-d

Alvaro Herrera wrote:

Show quoted text

David Ford dijo:

I wish everyone would use the same syntax...it's getting to the point
where you need a reference book for everybody's idea of how regex should
be done.

In Linux (well, at least in Mandrake) you can look at regex(7) for the
POSIX 1003.2 standard regexes, plus some things Henry Spencer added. His
implementation is the one used in Postgres internally, so it has some
value.

#6Martijn van Oosterhout
kleptog@svana.org
In reply to: David Ford (#5)
Re: regular expression question

On Tue, Jun 18, 2002 at 12:48:10AM -0400, David Ford wrote:

Yes, and honestly I rather prefer the POSIX syntax in most cases, but I
do like some of the shorthands, i.e. < (or \<) is so much easier to type
than "[[:<:]]", and the same for > v.s. "[[:>:]]". That's just silly.
This by the way is an extension.

I must admit that perl has some nice regex extensions and it would be nice
if postgres could use them (via libpcre). Then you could use \b, \s, \w,
etc.

However, Having looked into the regex language proposed for Perl 6, I think
that's going way over the top. Perl 5 is fine.
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/

Show quoted text

There are 10 kinds of people in the world, those that can do binary
arithmetic and those that can't.

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Martijn van Oosterhout (#6)
Re: regular expression question

Martijn van Oosterhout <kleptog@svana.org> writes:

I must admit that perl has some nice regex extensions and it would be nice
if postgres could use them (via libpcre). Then you could use \b, \s, \w,
etc.

If you want perl-style regexps, write yourself a one-liner plperl
function. End of problem...

regards, tom lane