473,503 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python regular expression

Hi,

As I understand it, python uses a pcre engine to work with regular
expression.
My question is, then, why expressions like :
>>re.compile('asd|(?-i:QWE)', re.I)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/sre.py", line 180, in compile
return _compile(pattern, flags)
File "/usr/lib/python2.4/sre.py", line 227, in _compile
raise error, v # invalid expression
sre_constants.error: unexpected end of pattern

don't work? They are ok in perl...

Thanks in advance.

Dec 5 '06 #1
1 2823
Wehrdamned wrote:
As I understand it, python uses a pcre engine to work with regular
expression.
[...]
My question is, then, why expressions like :
>>>re.compile('asd|(?-i:QWE)', re.I)
[...]
don't work? They are ok in perl...
From http://docs.python.org/lib/module-re.html:

This module provides regular expression matching operations
*similar* to those found in Perl.

Similar != the same. See http://docs.python.org/lib/re-syntax.html for
details about valid syntax for regular expressions in Python.

Cheers,
--
Roberto Bonvallet
Dec 5 '06 #2

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

Similar topics

18
2791
by: K_Lee | last post by:
I documented the regex internal implementation code for both Tcl and Python. As much as I like Tcl, I like Python's code much more. Tcl's Stub interface to the external commands is confusing to...
4
2192
by: pekka niiranen | last post by:
Hi there, I have perl script that uses dynamically constructed regular in this way: ------perl code starts ---- $result ""; $key = AAA\?01; $key = quotemeta $key; $line = " ...
75
4582
by: Xah Lee | last post by:
http://python.org/doc/2.4.1/lib/module-re.html http://python.org/doc/2.4.1/lib/node114.html --------- QUOTE The module defines several functions, constants, and an exception. Some of the...
3
9721
by: Vibha Tripathi | last post by:
Hi Folks, I put a Regular Expression question on this list a couple days ago. I would like to rephrase my question as below: In the Python re.sub(regex, replacement, subject)...
9
4501
by: Dieter Vanderelst | last post by:
Dear all, I'm currently comparing Python versus Perl to use in a project that involved a lot of text processing. I'm trying to determine what the most efficient language would be for our...
19
2288
by: Davy | last post by:
Hi all, I am a C/C++/Perl user and want to switch to Python (I found Python is more similar to C). Does Python support robust regular expression like Perl? And Python and Perl's File...
5
2300
by: Avi Kak | last post by:
Folks, Does regular expression processing in Python allow for executable code to be embedded inside a regular expression? For example, in Perl the following two statements $regex =...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7089
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...
0
7282
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,...
0
7463
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...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.