[Python-de] re.split und Unicode in Python 3

Stefan Behnel python-de at behnel.de
Fr Jul 29 10:57:18 EDT 2016


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



Mehr Informationen über die Mailingliste python-de