dbTalk Databases Forums  

problem with regex

comp.databases.postgresql comp.databases.postgresql


Discuss problem with regex in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Anselmo Canfora
 
Posts: n/a

Default problem with regex - 01-22-2010 , 05:54 AM






Hi, in PG 8.3 I have the following issue:

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\.3\.6\.1\.4\.1\.9\.1\.\d*)', 'g');
substring
-----------

(1 row)

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\.3\.6\.1\.4\.1\.9\.1\.[^\.]*)', 'g');
substring
---------------------
1.3.6.1.4.1.9.1.182
(1 row)

why \d it is (it seems) not recognised? what mistake am I making?

Thanks,

Anselmo

Reply With Quote
  #2  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: problem with regex - 01-22-2010 , 08:38 AM






On Fri, 22 Jan 2010 11:54:05 +0100, Anselmo Canfora wrote:

Quote:
Hi, in PG 8.3 I have the following issue:

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\.3\.6\.1\.4\.1\.9\.1\.\d*)', 'g');
substring
-----------

(1 row)

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\.3\.6\.1\.4\.1\.9\.1\.[^\.]*)', 'g');
substring
---------------------
1.3.6.1.4.1.9.1.182
(1 row)

why \d it is (it seems) not recognised? what mistake am I making?

Thanks,

Anselmo
Anselmo, you need to double your escape like this:
postgres=# select substring('1.3.6.1.4.1.9.1.182',
E'(1.3.6.1.4.1.9.1.\\d+)');

substring
---------------------
1.3.6.1.4.1.9.1.182
(1 row)

postgres=#


That escape doubling is annoying but is documented.
--
http://mgogala.freehostia.com

Reply With Quote
  #3  
Old   
Anselmo Canfora
 
Posts: n/a

Default Re: problem with regex - 01-22-2010 , 11:36 AM



Il 22/01/2010 14.38, Mladen Gogala ha scritto:
Quote:
On Fri, 22 Jan 2010 11:54:05 +0100, Anselmo Canfora wrote:

Hi, in PG 8.3 I have the following issue:

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\.3\.6\.1\.4\.1\.9\.1\.\d*)', 'g');
substring
-----------

(1 row)

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\.3\.6\.1\.4\.1\.9\.1\.[^\.]*)', 'g');
substring
---------------------
1.3.6.1.4.1.9.1.182
(1 row)

why \d it is (it seems) not recognised? what mistake am I making?

Thanks,

Anselmo

Anselmo, you need to double your escape like this:
postgres=# select substring('1.3.6.1.4.1.9.1.182',
E'(1.3.6.1.4.1.9.1.\\d+)');

substring
---------------------
1.3.6.1.4.1.9.1.182
(1 row)

postgres=#


That escape doubling is annoying but is documented.
I noticed that, it is that when I try to double escape to dots too (I
want the literal dot, not the any-char wildcard) it does not work.

Reply With Quote
  #4  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: problem with regex - 01-22-2010 , 03:15 PM



On Fri, 22 Jan 2010 17:36:42 +0100, Anselmo Canfora wrote:

Quote:
Il 22/01/2010 14.38, Mladen Gogala ha scritto:
On Fri, 22 Jan 2010 11:54:05 +0100, Anselmo Canfora wrote:

Hi, in PG 8.3 I have the following issue:

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\.3\.6\.1\.4\.1\.9\.1\.\d*)', 'g');
substring

Hmmm, I tried your example without the ending 'g' and it works. What is
that, anyway?

scott=> select substring('1.3.6.1.4.1.9.1.182',
E'(1\.3\.6\.1\.4\.1\.9\.1\.\\d*)');
substring
---------------------
1.3.6.1.4.1.9.1.182
(1 row)

scott=>




--
http://mgogala.byethost5.com

Reply With Quote
  #5  
Old   
Anselmo Canfora
 
Posts: n/a

Default Re: problem with regex - 01-22-2010 , 05:38 PM



Il 22/01/2010 21.15, Mladen Gogala ha scritto:
Quote:
On Fri, 22 Jan 2010 17:36:42 +0100, Anselmo Canfora wrote:

Il 22/01/2010 14.38, Mladen Gogala ha scritto:
On Fri, 22 Jan 2010 11:54:05 +0100, Anselmo Canfora wrote:

Hi, in PG 8.3 I have the following issue:

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\.3\.6\.1\.4\.1\.9\.1\.\d*)', 'g');
substring


Hmmm, I tried your example without the ending 'g' and it works. What is
that, anyway?

scott=> select substring('1.3.6.1.4.1.9.1.182',
E'(1\.3\.6\.1\.4\.1\.9\.1\.\\d*)');
substring
---------------------
1.3.6.1.4.1.9.1.182
(1 row)

scott=
'g' is a regex modification that should stand for "greedy". In Perl
regexps this one instructs the parser to extract as many atoms as many
match the expression, instead of stopping on first one.
In your example one should use double backslashes for dots too, anyway
you found the culprit, actually removing 'g' works:

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\\.3\\.6\\.1\\.4\\.1\\.\\d+)', 'g');
substring
-----------

(1 row)

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\\.3\\.6\\.1\\.4\\.1\\.\\d+)');
substring
---------------
1.3.6.1.4.1.9
(1 row)

this one seems to me a behavior not adherent to regexp "standards".
Thank you very much for the help.

Reply With Quote
  #6  
Old   
Jasen Betts
 
Posts: n/a

Default Re: problem with regex - 01-24-2010 , 04:24 AM



On 2010-01-22, Anselmo Canfora <spam (AT) mm (DOT) st> wrote:
Quote:
Il 22/01/2010 21.15, Mladen Gogala ha scritto:
On Fri, 22 Jan 2010 17:36:42 +0100, Anselmo Canfora wrote:

Il 22/01/2010 14.38, Mladen Gogala ha scritto:
On Fri, 22 Jan 2010 11:54:05 +0100, Anselmo Canfora wrote:

Hi, in PG 8.3 I have the following issue:

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\.3\.6\.1\.4\.1\.9\.1\.\d*)', 'g');
substring


Hmmm, I tried your example without the ending 'g' and it works. What is
that, anyway?

scott=> select substring('1.3.6.1.4.1.9.1.182',
E'(1\.3\.6\.1\.4\.1\.9\.1\.\\d*)');
substring
---------------------
1.3.6.1.4.1.9.1.182
(1 row)

scott=

'g' is a regex modification that should stand for "greedy". In Perl
regexps this one instructs the parser to extract as many atoms as many
match the expression, instead of stopping on first one.
In your example one should use double backslashes for dots too, anyway
you found the culprit, actually removing 'g' works:

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\\.3\\.6\\.1\\.4\\.1\\.\\d+)', 'g');
substring
-----------

(1 row)

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\\.3\\.6\\.1\\.4\\.1\\.\\d+)');
substring
---------------
1.3.6.1.4.1.9
(1 row)

this one seems to me a behavior not adherent to regexp "standards".
Thank you very much for the help.
I cannot find PG documentation for a form of substring taking three text
arguments separated by comma.

however, /df+ gives me:

Schema | pg_catalog
Name | substring
Result data type | text
Argument data types | text, text, text
Volatility | immutable
Owner | postgres
Language | sql
Source code | select pg_catalog.substring($1, pg_catalog.similar_escape($2, $3))
Description | extracts text matching SQL99 regular expression

it seems to be a SQL99 compatibility function, possibly an alias for

substring(string from pattern for escape)

yup, after minimal testing that seems to be the one.


--- news://freenews.netfront.net/ - complaints: news (AT) netfront (DOT) net ---

Reply With Quote
  #7  
Old   
Anselmo Canfora
 
Posts: n/a

Default Re: problem with regex - 01-24-2010 , 07:24 AM



Il 24/01/2010 10.24, Jasen Betts ha scritto:
Quote:
On 2010-01-22, Anselmo Canfora<spam (AT) mm (DOT) st> wrote:
Il 22/01/2010 21.15, Mladen Gogala ha scritto:
On Fri, 22 Jan 2010 17:36:42 +0100, Anselmo Canfora wrote:

Il 22/01/2010 14.38, Mladen Gogala ha scritto:
On Fri, 22 Jan 2010 11:54:05 +0100, Anselmo Canfora wrote:

Hi, in PG 8.3 I have the following issue:

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\.3\.6\.1\.4\.1\.9\.1\.\d*)', 'g');
substring


Hmmm, I tried your example without the ending 'g' and it works. What is
that, anyway?

scott=> select substring('1.3.6.1.4.1.9.1.182',
E'(1\.3\.6\.1\.4\.1\.9\.1\.\\d*)');
substring
---------------------
1.3.6.1.4.1.9.1.182
(1 row)

scott=

'g' is a regex modification that should stand for "greedy". In Perl
regexps this one instructs the parser to extract as many atoms as many
match the expression, instead of stopping on first one.
In your example one should use double backslashes for dots too, anyway
you found the culprit, actually removing 'g' works:

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\\.3\\.6\\.1\\.4\\.1\\.\\d+)', 'g');
substring
-----------

(1 row)

db_atm=# select substring('1.3.6.1.4.1.9.1.182',
E'(1\\.3\\.6\\.1\\.4\\.1\\.\\d+)');
substring
---------------
1.3.6.1.4.1.9
(1 row)

this one seems to me a behavior not adherent to regexp "standards".
Thank you very much for the help.

I cannot find PG documentation for a form of substring taking three text
arguments separated by comma.

however, /df+ gives me:

Schema | pg_catalog
Name | substring
Result data type | text
Argument data types | text, text, text
Volatility | immutable
Owner | postgres
Language | sql
Source code | select pg_catalog.substring($1, pg_catalog.similar_escape($2, $3))
Description | extracts text matching SQL99 regular expression

it seems to be a SQL99 compatibility function, possibly an alias for

substring(string from pattern for escape)

yup, after minimal testing that seems to be the one.


--- news://freenews.netfront.net/ - complaints: news (AT) netfront (DOT) net ---
My fault, it is actually so. I had a too much rapid survey on docs.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.