regexp problem

Started by Gauthier, Daveabout 15 years ago4 messagesgeneral
Jump to latest
#1Gauthier, Dave
dave.gauthier@intel.com

I want to include '[', ']', and '.' in a list of permitted chars in a regexp. This doesn's seem to work...

select 'abc.def[0]' ~ E'^[a-zA-Z0-9_\.\[\]]+$';
?collum?
--------
f
(1 row)

Help!

#2Steve Crawford
scrawford@pinpointresearch.com
In reply to: Gauthier, Dave (#1)
Re: regexp problem

On 02/24/2011 10:25 AM, Gauthier, Dave wrote:

select 'abc.def[0]' ~ E'^[a-zA-Z0-9_*\.\[\]*]+$';

Try:
E'^[a-zA-Z0-9._\\[\\]]+$'

The "outer" level of parsing turns that into '^[a-zA-Z0-9._\[\]]+$'
which is the regex you want. Also, I'm *pretty sure* you don't need to
escape the '.' within a character class.

Cheers,
Steve

#3Gauthier, Dave
dave.gauthier@intel.com
In reply to: Steve Crawford (#2)
Re: regexp problem

Yup, that did it. And you're right, you don't need to escape the '.'.
So the extra \ is needed because of the single quotes string. Arrrrgggg..... :-)

Thanks Steve !

From: Steve Crawford [mailto:scrawford@pinpointresearch.com]
Sent: Thursday, February 24, 2011 1:40 PM
To: Gauthier, Dave
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] regexp problem

On 02/24/2011 10:25 AM, Gauthier, Dave wrote:
select 'abc.def[0]' ~ E'^[a-zA-Z0-9_\.\[\]]+$';

Try:
E'^[a-zA-Z0-9._\\[\\]]+$'

The "outer" level of parsing turns that into '^[a-zA-Z0-9._\[\]]+$' which is the regex you want. Also, I'm *pretty sure* you don't need to escape the '.' within a character class.

Cheers,
Steve

#4Merlin Moncure
mmoncure@gmail.com
In reply to: Gauthier, Dave (#3)
Re: regexp problem

On Thu, Feb 24, 2011 at 2:12 PM, Gauthier, Dave <dave.gauthier@intel.com> wrote:

Yup, that did it.  And you're right, you don't need to escape the '.'.

So the extra \ is needed because of the single quotes string.
Arrrrgggg.....  :-)

Yes...highly advise dollar quoting whenever dealing with regex.

merlin