regular expression question
regular expression question
От:
Parker 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
Re: regular expression question
От:
Alvaro Herrera <alvherre@atentus.com>
Дата:
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 () "La vida es para el que se aventura"
Re: regular expression question
От:
David Ford <david+cert@blue-labs.org>
Дата:
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: >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. > > >
Re: regular expression question
От:
Alvaro Herrera <alvherre@atentus.com>
Дата:
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 () "El dia que dejes de cambiar dejaras de vivir"
Re: regular expression question
От:
David Ford <david+cert@blue-labs.org>
Дата:
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: >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. > > >
Re: regular expression question
От:
Martijn van Oosterhout <kleptog@svana.org>
Дата:
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 http://svana.org/kleptog/ > There are 10 kinds of people in the world, those that can do binary > arithmetic and those that can't.
Re: regular expression question
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Martijn van Oosterhout 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