Re: Quick Regex Question

From: Howard Cole <howardnews(at)selestial(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Quick Regex Question
Date: 2007-12-20 12:26:40
Message-ID: 476A5F80.30403@selestial.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Terry Fielder wrote:
> Why do you need to? Check for the beginning of the string BEFORE the
> set brackets. The point of set brackets is "match from a set of
> chars". Since "beginning of string" can only match one place, it has
> no meaning as a member of a set. Or in other words, if it has
> meaning, it needs to be matched FIRST out of the set, and therefore
> you can just remove from the set and put before the set brackets.
>> or am I forced to use the (^| ) syntax?
>>
>> Is it just me or are regular expressions crazy?
> Complicated, not crazy.
>
> Terry
Hmm. Still think they are crazy - sometimes the characters are
interpreted as literals - other times not? Thats crazy in my book! It
would make more sense to me if you had to escape the characters inside
the [ ] as they seem to be everywhere else. There is possibly a good
reason for this - But perhaps they are just crazy!!!
;)

I am trying to match the beginning of a name, so to search for
'how' in 'Howard Cole' should match
'col' in 'Howard Cole' should match
'ole' in 'Howard Cole' should NOT match,

So using ~* '(^| )col' works for me! As would '(^col| col)' etc.

Just as an aside, is there a function that escapes my search string so
that any special regex characters are replaced? For example, if I was
going to search for 'howard.cole' in the search string it would convert
to 'howard[:.:]cole' or 'howard\.cole' - and then convert that into a
postgres compatible string!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2007-12-20 12:41:46 Re: foreign key constraint, planner ignore index.
Previous Message Marek Szczypek 2007-12-20 12:24:25 Change of the data directory on Ubuntu 7.04