How do I specify a range of unicode characters from ' ' (space) to \u00D7FF?
I have a regular expression like r'[\u0020-\u00D7FF]' and it won’t compile saying that it’s a bad range. I am new to Unicode regular expressions so I haven’t had this problem before.
Is there a way to make this compile or a regular expression that I’m forgetting or haven’t learned yet?
The syntax of your unicode range will not do what you expect.
The raw
r''string prevents\uescapes from being parsed, and the regex engine will not do this. The only range in this set is[0-\]:Making it a Unicode literal causes
\uparsing while leaving other backslashes alone (although that’s not a concern here), but the leading zeroes are messing it up. The syntax is\uxxxxor\Uxxxxxxxx, so it’s parsed as “\u00d7,f,f“.Removing the leading zeroes or switching to
\U0000d7ffwill fix it: