Skip site navigation (1) Skip section navigation (2)

Re: Regex Character-Class

From: Thomas Pundt <mlists(at)rp-online(dot)de>
To: Henry <henry(at)zen(dot)co(dot)za>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Regex Character-Class
Date: 2009-06-30 07:27:29
Message-ID: 4A49BE61.3060506@rp-online.de (view raw or flat)
Thread:
Lists: pgsql-general
Henry schrieb:
> I must be missing something here:
> 
> SELECT '1.1.1.1' ~ E'^\d+';
> 
> returns FALSE, when I would expect TRUE, as for:
> 
> SELECT '1.1.1.1'  ~ E'^[[:digit:]]+';
> 
> ie, '[[:digit:]]'  !=  '\d'
> 
> In config, "regex_flavor = advanced".
> 
> Any ideas?

Yes; you have to escape the backslash character:

=> SELECT '1.1.1.1' ~ E'^\\d+';
  ?column?
----------
  t
(1 row)


See the documentation for this 
(http://www.postgresql.org/docs/8.3/interactive/functions-matching.html):

   Note:  Remember that the backslash (\) already has a special meaning
   in PostgreSQL string literals. To write a pattern constant that
   contains a backslash, you must write two backslashes in the statement,
   assuming escape string syntax is used (see Section 4.1.2.1).

Ciao,
Thomas

In response to

pgsql-general by date

Next:From: Dave PageDate: 2009-06-30 07:35:09
Subject: Re: masking the code
Previous:From: A. KretschmerDate: 2009-06-30 07:23:26
Subject: Re: Regex Character-Class

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group