473,799 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2717
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 YourEmailAddres sHere" to ma*******@postg resql.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 YourEmailAddres sHere" to ma*******@postg resql.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
2602
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
2213
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 perl and posix? And for those POSIX experts, what do the following do? is for non-english languages and such?
0
3366
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, etc. In the beginning I thought I had to use the POSIX module, using SigSet SigAction, sigprocmask etc. for a rather paranoid approach. Then I've rea
2
3600
by: raxitsheth | last post by:
Hello All... I am using Posix Thread. class Parent { public: virtual void* func(void *)=0;
11
3016
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, but I have maybe missed something. Thanks in advance.
6
2735
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 ftp://ftp.ctd.comsat.com/pub/ seems dead. Does any old-timer (<wink>) have a copy of this package ?
23
5719
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() { : : do stuff
8
5636
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 POSIX). I tried to implement myself clrscr() with system("cls"), but the program compiles ok, but during the running it will show: sh: cls: command not found
23
3353
by: asit | last post by:
what is the difference between portable C, posix C and windows C ???
0
9550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10495
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10269
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7573
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4148
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.