Why does this work:
>>> ss
u'\U0001f300'
>>> r = re.compile(u"[u'\U0001F300-\U0001F5FF']+", re.UNICODE)
>>> r.search(ss) # this works
<_sre.SRE_Match object at 0x7f359acf03d8>
But this doesn't:
>>> r = re.compile("[u'\U0001F300-\U0001F5FF']+", re.UNICODE)
>>> r.search(ss) # this doesn't
Based on Ignacio's answer below, this also works:
>>> r = re.compile(u"[\U0001F300-\U0001F5FF]+", re.UNICODE)
>>> r.search(ss)
<_sre.SRE_Match object at 0x7f359acf03d8>
u'..'
inside the character classes are not doing anything except includingu
as a legal match - along with the apostrophe, twice.u
, single apostrophe, and any character fromU+1F300
toU+1F5FF
".ss
contains the single codepointU+1F300
, which meets the requirements.[ax-z]
matches any ofa
,x
,y
orz
. Your character class matchesu
or'
or U+1F300 or U+1F301 or ... or U+1F5FE or U+1F5FF.re.UNICODE
only affects the behavior of\d
,\s
,\w
and has nothing to do with the Unicode/byte semantic of the regex engine.