2 ms·
I don't think the regex package implements this. At least the hex notation is not supported: >>> import regex >>> regex.compile(r'\u{3040}') Traceback (m
by jwilk 8y ago
I don't think the regex package implements this. At least the hex notation is not supported:
>>> import regex
>>> regex.compile(r'\u{3040}')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/regex.py", line 345, in compile
return _compile(pattern, flags, kwargs)
File "/usr/lib/python3/dist-packages/regex.py", line 507, in _compile
caught_exception.pos)
_regex_core.error: incomplete escape \u at position 2
- rspeer 8y agoHmm, okay. It seems to just use Python's unicode escape syntax, instead of what the standard says. But the package does support things like the complex character classes, and identifying word boundaries. (The algorithm for identifying word boundaries in most languages without ASCII/English assumptions is quite complex and useful, as I can say from having tried to reinvent half of it before learning about the standard and the regex package. It's not a panacea -- it won't do anything useful with languages where word boundaries require lexical knowledge, like Chinese, Japanese, and Thai -- but other than that it handles all the edge cases you never would have thought of.)
- burntsushi 8y agoYeah, basically, the standard is a little sneaky on this point. It doesn't actually require a specific syntax, but rather, simply that being able to write Unicode codepoints in hexadecimal representation is possible. Notice that it says, "... shall supply a mechanism ..." rather than "this mechanism." Of course, it's probably a good idea to follow the sample syntax provided. :-)