[Python-bugs-list] [ python-Bugs-406815 ] python2.1b re bug (.*)?

noreply@sourceforge.net noreply@sourceforge.net
Sun, 09 Dec 2001 08:34:10 -0800


Bugs item #406815, was opened at 2001-03-07 12:32
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=406815&group_id=5470

Category: Regular Expressions
Group: None
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Fredrik Lundh (effbot)
Summary: python2.1b re bug (.*)?

Initial Comment:
The script below works per expectation with python1.5.
It fails with python2.1b1

% python2.1 gar 
Traceback (most recent call last):
  File "gar", line 9, in ?
    mob = re.search("== Parameters ==\n(.*)?\s*$",
output, re.S)
  File "/usr/local/lib/python2.1/sre.py", line 55, in
search
    return _compile(pattern, flags).search(string)
  File "/usr/local/lib/python2.1/sre.py", line 131, in
_compile
    raise error, v # invalid expression
sre_constants.error: nothing to repeat

Move "?" inside the parens and it works. Replace the
"*" with a "+" and it works (at least for this example
input).

import re

output = """
Using 
== Parameters ==
line1
line2
"""
mob = re.search("== Parameters ==\n(.*)?\s*$", output,
re.S)
print mob.groups()



----------------------------------------------------------------------

>Comment By: Fredrik Lundh (effbot)
Date: 2001-12-09 08:34

Message:
Logged In: YES 
user_id=38376

the expression is ambigous, and could mean either "(.+)?" 
(if you want an undefined group for an empty match) 
or "(.*)" (if you want the group to contain an empty 
string).

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=406815&group_id=5470