regexp compilation error

Ovidiu Deac ovidiudeac at gmail.com
Fri Sep 30 11:26:52 CEST 2011


$ python --version
Python 2.6.6


On Fri, Sep 30, 2011 at 12:18 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Fri, Sep 30, 2011 at 7:10 PM, Ovidiu Deac <ovidiudeac at gmail.com> wrote:
>> I have the following regexp which fails to compile. Can somebody explain why?
>>
>>>>> re.compile(r"""^(?: [^y]* )*""", re.X)
>> Traceback (most recent call last):
>>  File "<stdin>", line 1, in <module>
>>  File "/usr/lib/python2.6/re.py", line 190, in compile
>>    return _compile(pattern, flags)
>>  File "/usr/lib/python2.6/re.py", line 245, in _compile
>>    raise error, v # invalid expression
>> sre_constants.error: nothing to repeat
>>
>> Is this a bug or a feature?
>
> What version of Python are you using? It looks like you're running in
> a Python 3 interpreter, and loading a Python 2 module (as shown by the
> python2.6 in the path and the Python 2 error-raise syntax). You may
> have a problem with your module path.
>
> Running that line of code in Python 3.2 for Windows produces this error:
>
>>>> re.compile(r"""^(?: [^y]* )*""", re.X)
> Traceback (most recent call last):
>  File "<pyshell#465>", line 1, in <module>
>    re.compile(r"""^(?: [^y]* )*""", re.X)
>  File "C:\Python32\lib\re.py", line 206, in compile
>    return _compile(pattern, flags)
>  File "C:\Python32\lib\re.py", line 256, in _compile
>    return _compile_typed(type(pattern), pattern, flags)
>  File "C:\Python32\lib\functools.py", line 180, in wrapper
>    result = user_function(*args, **kwds)
>  File "C:\Python32\lib\re.py", line 268, in _compile_typed
>    return sre_compile.compile(pattern, flags)
>  File "C:\Python32\lib\sre_compile.py", line 495, in compile
>    code = _code(p, flags)
>  File "C:\Python32\lib\sre_compile.py", line 480, in _code
>    _compile(code, p.data, flags)
>  File "C:\Python32\lib\sre_compile.py", line 74, in _compile
>    elif _simple(av) and op is not REPEAT:
>  File "C:\Python32\lib\sre_compile.py", line 359, in _simple
>    raise error("nothing to repeat")
> sre_constants.error: nothing to repeat
>
> Does that help at all?
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list