re.split und Unicode in Python 3

Ich habe gerade dieses merkwürdige Verhalten von Python 3.5 festgestellt: Python 3.5.1+ (default, Mar 30 2016, 22:46:26) [GCC 5.3.1 20160330] on linux Type "help", "copyright", "credits" or "license" for more information.
import re s = 'One\u2003Two'
re.search('\s+', s) <_sre.SRE_Match object; span=(3, 4), match='\u2003'> re.search('\s+', s, re.ASCII)
^^^ # --> No match
re.split('\s+', s) ['One', 'Two'] re.split('\s+', s, re.ASCII) ['One', 'Two']
Bug? Zum Verständnis: '\u2003' == em space, also ein Whitespace-Char in Unicode. Chris

Christopher Arndt schrieb am 29.07.2016 um 16:45:
Ich habe gerade dieses merkwürdige Verhalten von Python 3.5 festgestellt:
Python 3.5.1+ (default, Mar 30 2016, 22:46:26) [GCC 5.3.1 20160330] on linux Type "help", "copyright", "credits" or "license" for more information.
import re s = 'One\u2003Two'
re.search('\s+', s) <_sre.SRE_Match object; span=(3, 4), match='\u2003'> re.search('\s+', s, re.ASCII)
^^^ # --> No match
re.split('\s+', s) ['One', 'Two'] re.split('\s+', s, re.ASCII) ['One', 'Two']
Bug?
Nein.
re.split('\s+', s, flags=re.ASCII) ['One\u2003Two']
Die Signatur von re.split() ist re.split(pattern, string, maxsplit=0, flags=0) https://docs.python.org/3/library/re.html#re.split Stefan

Am 29.07.2016 um 16:57 schrieb Stefan Behnel:
Die Signatur von re.split() ist
re.split(pattern, string, maxsplit=0, flags=0)
Ah, dachte ich mir doch, dass ich was übersehen habe. Ich sollte mir wohl angewöhnen, die Flags immer per keyword arg zu übergeben, auch bei den anderen re Funktionen/Methoden. Thx, Chris
participants (2)
-
Christopher Arndt
-
Stefan Behnel