Postgres friendly RegEx?

Started by Jon Asherover 19 years ago5 messagesgeneral
Jump to latest
#1Jon Asher
jon.asher@gmail.com

Anyone care to correct this regex for PostgreSQL? It works in C++ but
Postgres have no love for it:

-{0,1}\d*\.{0,1}\d+\^{0,1}\d*\.{0,1}\d+

This regex accepts (any num)^(pos num) such as:
45.2^3
-45.2^3
10^2.5

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jon Asher (#1)
Re: Postgres friendly RegEx?

"Jon Asher" <jon.asher@gmail.com> writes:

Anyone care to correct this regex for PostgreSQL? It works in C++ but
Postgres have no love for it:

-{0,1}\d*\.{0,1}\d+\^{0,1}\d*\.{0,1}\d+

It works fine in Postgres, AFAICT. Maybe you forgot to double the
backslashes in a string literal? Otherwise, be more specific about
your problem.

regards, tom lane

#3Jeremy Harris
jgh@wizmail.org
In reply to: Tom Lane (#2)
Re: Postgres friendly RegEx?

You don't give a pg version.....

It looks legal to me as of 8.1.

Try replacing all the "{0,1}" with "?" - but
check the manual for "regex_flavor" too.
Is there any chance you're in "basic" mode?

- Jeremy

#4Jon Asher
jon.asher@gmail.com
In reply to: Tom Lane (#2)
Re: Postgres friendly RegEx?

In Postgres, it appears to be returning false positives:

select * from
(select '52'::varchar As val) d
where d.val ~ '-{0,1}\\d*\\.{0,1}\\d+\\^{0,1}\\d*\\.{0,1}\\d+'

returns a record.
In C++ only such values match: 45.2^3 or -45.2^3 or 10^2.5

Show quoted text

On 12/12/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:

"Jon Asher" <jon.asher@gmail.com> writes:

Anyone care to correct this regex for PostgreSQL? It works in C++ but
Postgres have no love for it:

-{0,1}\d*\.{0,1}\d+\^{0,1}\d*\.{0,1}\d+

It works fine in Postgres, AFAICT. Maybe you forgot to double the
backslashes in a string literal? Otherwise, be more specific about
your problem.

regards, tom lane

#5Jon Asher
jon.asher@gmail.com
In reply to: Jon Asher (#4)
Re: Postgres friendly RegEx?

Please ignore, my mistake in the translation to Pg regex !

Show quoted text

On 12/12/06, Jon Asher <jon.asher@gmail.com> wrote:

In Postgres, it appears to be returning false positives:

select * from
(select '52'::varchar As val) d
where d.val ~ '-{0,1}\\d*\\.{0,1}\\d+\\^{0,1}\\d*\\.{0,1}\\d+'

returns a record.
In C++ only such values match: 45.2^3 or -45.2^3 or 10^2.5

On 12/12/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:

"Jon Asher" <jon.asher@gmail.com> writes:

Anyone care to correct this regex for PostgreSQL? It works in C++ but

Postgres have no love for it:

-{0,1}\d*\.{0,1}\d+\^{0,1}\d*\.{0,1}\d+

It works fine in Postgres, AFAICT. Maybe you forgot to double the
backslashes in a string literal? Otherwise, be more specific about
your problem.

regards, tom lane