[New-bugs-announce] [issue23318] (compiled RegEx).split gives unexpected results if () in pattern

Dave Notman report at bugs.python.org
Sun Jan 25 18:31:37 CET 2015


New submission from Dave Notman:

# Python 3.3.1 (default, Sep 25 2013, 19:30:50)
# Linux 3.8.0-35-generic #50-Ubuntu SMP Tue Dec 3 01:25:33 UTC 2013 i686 i686 i686 GNU/Linux

import re

splitter = re.compile( r'(\s*[+/&;,]\s*)|(\s+and\s+)' )
ll = splitter.split( 'Dave & Sam, Jane and Zoe' )
print(repr(ll))

print( 'Try again with revised RegEx' )
splitter = re.compile( r'(?:(?:\s*[+/&;,]\s*)|(?:\s+and\s+))' )
ll = splitter.split( 'Dave & Sam, Jane and Zoe' )
print(repr(ll))

Results:
['Dave', ' & ', None, 'Sam', ', ', None, 'Jane', None, ' and ', 'Zoe']
Try again with revised RegEx
['Dave', 'Sam', 'Jane', 'Zoe']

----------
components: Regular Expressions
messages: 234677
nosy: dnotmanj, ezio.melotti, mrabarnett
priority: normal
severity: normal
status: open
title: (compiled RegEx).split gives unexpected results if () in pattern
type: behavior
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23318>
_______________________________________


More information about the New-bugs-announce mailing list