473,326 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

POSIX RE starting with a (

Hi,

Just noticed something funny with the POSIX Regular expressions and
wondered if it is a bug, or whether I am doing something wrong. I am
using the POSIX RE in a function that is used in several places so would
have to put some nasty if statement in there for this side case if there
is not work around.

================================================== ====================
intranet=# select track_id, track_name from ms_track where track_name
like '(%';
track_id | track_name
----------+---------------------------------
1294 | (I Can''t Get No) Satisfaction
1340 | (Hidden Track)
1503 | (Nice Dream)
1942 | (I) Get Lost
(4 rows)

intranet=# select track_name from ms_track where track_name ~ '^\(';
ERROR: invalid regular expression: parentheses () not balanced
intranet=# select track_name from ms_track where track_name ~ '^(';
ERROR: invalid regular expression: parentheses () not balanced
intranet=# select track_name from ms_track where track_name ~ '^\(';
ERROR: invalid regular expression: parentheses () not balanced
================================================== ====================

Now I have tried a similar query using the PHP POSIX Regular Expressions
and it accepts the sequence '^\(' and matches correctly. Is this a
"feature" of PG that cannot be worked around easily?

Any thoughts?

Thanks

Nick

P.S. Thanks a lot guys for all the hard work on 8.0, looks good to me.
Lots of really useful features, PITR, Win32, Nested transactions. Good
work guys!
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #1
5 2680
Nick Barr wrote:
Hi,

Just noticed something funny with the POSIX Regular expressions and
wondered if it is a bug, or whether I am doing something wrong. I am
using the POSIX RE in a function that is used in several places so would
have to put some nasty if statement in there for this side case if there
is not work around.

================================================== ====================
intranet=# select track_id, track_name from ms_track where track_name
like '(%';
track_id | track_name
----------+---------------------------------
1294 | (I Can''t Get No) Satisfaction
1340 | (Hidden Track)
1503 | (Nice Dream)
1942 | (I) Get Lost
(4 rows)

intranet=# select track_name from ms_track where track_name ~ '^\(';
ERROR: invalid regular expression: parentheses () not balanced
intranet=# select track_name from ms_track where track_name ~ '^(';
ERROR: invalid regular expression: parentheses () not balanced
intranet=# select track_name from ms_track where track_name ~ '^\(';
ERROR: invalid regular expression: parentheses () not balanced
================================================== ====================

Now I have tried a similar query using the PHP POSIX Regular Expressions
and it accepts the sequence '^\(' and matches correctly. Is this a
"feature" of PG that cannot be worked around easily?

Any thoughts?

Thanks

Nick

P.S. Thanks a lot guys for all the hard work on 8.0, looks good to me.
Lots of really useful features, PITR, Win32, Nested transactions. Good
work guys!


Sorry should of said I am running PG 7.4.3.
Nick
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #2
Nick Barr <ni***@chuckie.co.uk> writes:
intranet=# select track_name from ms_track where track_name ~ '^\(';
ERROR: invalid regular expression: parentheses () not balanced


You've forgotten that the string-literal parser will eat one level of
backslashing. You need

intranet=# select track_name from ms_track where track_name ~ '^\\(';

to get that backslash into the regex parser.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #3
On Wed, 2004-08-11 at 14:39, Nick Barr wrote:
Hi,

Just noticed something funny with the POSIX Regular expressions and
wondered if it is a bug, or whether I am doing something wrong. I am
using the POSIX RE in a function that is used in several places so would
have to put some nasty if statement in there for this side case if there
is not work around.

================================================== ====================
intranet=# select track_id, track_name from ms_track where track_name
like '(%';
track_id | track_name
----------+---------------------------------
1294 | (I Can''t Get No) Satisfaction
1340 | (Hidden Track)
1503 | (Nice Dream)
1942 | (I) Get Lost
(4 rows)

intranet=# select track_name from ms_track where track_name ~ '^\(';
ERROR: invalid regular expression: parentheses () not balanced
intranet=# select track_name from ms_track where track_name ~ '^(';
ERROR: invalid regular expression: parentheses () not balanced
intranet=# select track_name from ms_track where track_name ~ '^\(';
ERROR: invalid regular expression: parentheses () not balanced
================================================== ====================

Now I have tried a similar query using the PHP POSIX Regular Expressions
and it accepts the sequence '^\(' and matches correctly. Is this a
"feature" of PG that cannot be worked around easily?


You need to escape the backslash:

select track_name from ms_track where track_name ~ '^\\
(';
--
Oliver Elphick ol**@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"Be still before the LORD and wait patiently for him;
do not fret when men succeed in their ways, when they
carry out their wicked schemes."
Psalms 37:7
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #4
Tom Lane wrote:
Nick Barr <ni***@chuckie.co.uk> writes:
intranet=# select track_name from ms_track where track_name ~ '^\(';
ERROR: invalid regular expression: parentheses () not balanced

You've forgotten that the string-literal parser will eat one level of
backslashing. You need

intranet=# select track_name from ms_track where track_name ~ '^\\(';

to get that backslash into the regex parser.

regards, tom lane


Doh,

Thanks guys.
Nick
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #5
On Wed, Aug 11, 2004 at 03:28:17PM +0100, Nick Barr wrote:
================================================= =====================
intranet=# select track_id, track_name from ms_track where track_name
like '(%';
track_id | track_name
----------+---------------------------------
1294 | (I Can''t Get No) Satisfaction
1340 | (Hidden Track)
1503 | (Nice Dream)
1942 | (I) Get Lost
(4 rows)

intranet=# select track_name from ms_track where track_name ~ '^\(';
ERROR: invalid regular expression: parentheses () not balanced
intranet=# select track_name from ms_track where track_name ~ '^(';
ERROR: invalid regular expression: parentheses () not balanced
intranet=# select track_name from ms_track where track_name ~ '^\(';
ERROR: invalid regular expression: parentheses () not balanced
================================================= =====================

Now I have tried a similar query using the PHP POSIX Regular Expressions
and it accepts the sequence '^\(' and matches correctly. Is this a
"feature" of PG that cannot be worked around easily?


See the "Regular Expression Details" section of the PostgreSQL manual:

http://www.postgresql.org/docs/7.4/s...SYNTAX-DETAILS

The Note under Table 9-12 says, "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."

Try this:

SELECT track_name FROM ms_track WHERE track_name ~ '^\\(';

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
0
by: RN | last post by:
Hi, I don't know if this is the right place to ask this, but - what's the difference between posix and perl regular expressions? A good example is "aa|bb". Will this match "aa" or "ab" in...
0
by: steffen staehle | last post by:
Hi, I'm writing a server process which spawns child processes via fork This server process should keep track of the number of children stil running, do the necessary cleanup to avoid zombies,...
2
by: raxitsheth | last post by:
Hello All... I am using Posix Thread. class Parent { public: virtual void* func(void *)=0;
11
by: FiLH | last post by:
Hello, I would like to know if posix semaphores are inter processes or just semaphores for threads inside the same process. I have not seen it defined in the posix specification I have found,...
6
by: Sébastien Boisgérault | last post by:
Hi, I'm searching for a POSIX 1003.2 compatible regular expression engine. The Python binding "pregex" by Neal Becker may do the job, but I did not manage to download it as the original link...
23
by: Boltar | last post by:
Hi I'm writing a threading class using posix threads on unix with each thread being run by an object instance. One thing I'm not sure about is , if I do the following: myclass::~myclass() {...
8
by: Michele 'xjp' | last post by:
Hi there, I am using a POSIX-compliant system, Cygwin on Windows. I need the features of conio.h's getch() and clrscr(), but I can't compile programs with #include <conio.h(since conio.h is NOT...
23
by: asit | last post by:
what is the difference between portable C, posix C and windows C ???
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.