Title: re.VERBOSE doesn't respect whitespace in '( ?P...)'
Type: behavior Stage: resolved
Components: Library (Lib), Regular Expressions Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
Status: closed Resolution: duplicate
Dependencies: Superseder: re.VERBOSE whitespace behavior not completely documented
View: 15606
Assigned To: Nosy List: ezio.melotti, mrabarnett, roysmith
Priority: normal Keywords:

Created on 2013-02-11 19:39 by roysmith, last changed 2013-02-15 21:08 by ezio.melotti. This issue is now closed.

Messages (2)
msg181927 - (view) Author: Roy Smith (roysmith) Date: 2013-02-11 19:39
# Python 2.7.3
# Ubuntu 12.04

import re
pattern = r"( ?P<phrase>.*)"
regex = re.compile(pattern, re.VERBOSE)

The above raises an exception in re.compile():

Traceback (most recent call last):
  File "./", line 6, in <module>
    regex = re.compile(pattern, re.VERBOSE)
  File "/home/roy/env/python/lib/python2.7/", line 190, in compile
    return _compile(pattern, flags)
  File "/home/roy/env/python/lib/python2.7/", line 242, in _compile
    raise error, v # invalid expression
sre_constants.error: nothing to repeat

The problem appears to be that re.VERBOSE isn't ignoring the space after the "(".

Maybe this is a duplicate of issue15606 ?
msg181931 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2013-02-11 20:10
It does look like a duplicate to me.
Date User Action Args
2013-02-15 21:08:18ezio.melottisetstatus: open -> closed
superseder: re.VERBOSE whitespace behavior not completely documented
stage: resolved
resolution: duplicate
versions: + Python 3.2, Python 3.3, Python 3.4
2013-02-11 20:10:48mrabarnettsetmessages: + msg181931
2013-02-11 19:52:35ezio.melottisetnosy: + ezio.melotti, mrabarnett
components: + Regular Expressions
2013-02-11 19:39:08roysmithcreate