Unicode Regular Expressions
unicode.org
unicode.org
I think there are a lot of should’s because the Unicode consortium realizes that there will be variability in feature sets of regular expression libraries. http://unicode.org/reports/tr18/#Conformance has quite a few shall’s to counteract that, but still leaves implementations to pick and choose features, as long as they document that.
I also think it's clear from reading this document many times that it was very much informed by regex implementors. The text seems quite self-aware of the fact that some features may not be practical to implement in all scenarios.
It is certainly far from perfect, and I bet that if we got in a room together, we could vent about things in (or missing from) this document. But I am determined not to let perfection be the enemy of good, and this document has, at least in my experience, done much more good than harm.
It's just too complex a 'standard'. The amount of crap they had to 'retract' by the current version is telling, and features like 3.9 and 3.11 are speculative design by standards committee, which is the exact opposite of how these things should work. It's the ultimate unfunded mandate: "hooray, I'm writing a standard, why don't I shove some random crap in there that no-one implements now in existing libraries in the hope I get to set directions".
The standard should be minimal and well-defined. This is neither.
It's also preposterously self-important. Yeah, I'm so fascinated by the history of the Unicode standard I'm going to start introducing an "age" property so I can regex-match on when characters were entered. There's a certain attitude whereby these guys are just blithely shoveling junk into a standard that no-one needs. If you're desperate for all these exotic character properties put them in a godamn file as a character class and blat them in wherever you need them (yes, it would be nice if regex had macros).
Somewhere in all this nonsense is a good standard struggling to get out. They need to shit or get off the pot. Anything that they don't know how to do or that no-one knows how to do should be completely deleted. Anything that they offer 15 different choices as to how to do ... they need to figure out which is the best one and pick that. It's a standards documents, it's supposed to make choices, it's not a potted plant.
Some of the Level 3 features venture too far afield from Unicode, too, e.g., 3.11 is "implement YACC" and has nothing to do with Unicode and 3.7 is "implement a streaming regexp engine, we dare you" (challenge accepted, Unicode dweebs!).
So, it is a horrible standard by which to judge overall conformance, but no one really does that. I think the value is in lighting the way through a broad array of thorny Unicode topics. And I think that the implementor who grapples with a majority subset of the sensible topics will wind up with an engine that handles users' Unicode needs.
A lot of code points used in Indic languages are outside the `L` categories, and not having the Alphabetic property (and having both `\w` and the POSIX `:alpha:` match only within `L`) is a significant annoyance when parsing mixed-language text (in Julia, which uses PCRE2 as the backend for regex). Is PCRE2 particularly behind in Unicode property implementation, or is this par for the course in common regex engines today?
w.r.t. to Unicode support, it is fairly par for the course. There are some regex implementations that have very good Unicode support. Python's `regex` library (not `re` in the standard library) is very comprehensive with Unicode, and I think the regex library that `icgrep` uses is also fairly comprehensive. Both of those extend well into level 2 of UTS#18. Rust's regex library (the one I wrote) has fairly complete level 1 support with a few hiccups, but that is a somewhat recent development.
I imagine ICU's regex engine also has fairly complete UTS#18 support as well, although I've never used it myself. Similarly for Oniguruma.
icgrep is the only one of the above that I mention that doesn't have a reputation for being slow (and is actually quite fast). But... its toolchain dependencies are considerable.
PCRE2's Unicode support is pretty good, but definitely has its quirks. It definitely appears to support a limited set of properties, and appears mostly restricted to general categories and scripts, which gives a fair bit of breadth. You might be able to get close to \p{Alphabetic} by building its constituent parts: https://unicode.org/reports/tr44/#Alphabetic --- It looks like PCRE2 supports everything in Lowercase + Uppercase + Lt + Lm + Lo + Nl + Other_Alphabetic except for `Other_Alphabetic` (this is according to `man pcre2pattern`). Unfortunately, Other_Alphabetic is quite large, so it might be hard to just handjam that easily.
Interestingly, with all that said, PCRE2 does support a Unicode interpretation of \w, which is defined by Unicode to be: http://unicode.org/reports/tr18/#word
\p{alpha}
\p{gc=Mark}
\p{digit}
\p{gc=Connector_Punctuation}
\p{Join_Control}
which is a superset of \p{Alphabetic} (\p{alpha} is an alias for \p{alphabetic}). Note though that \w by default in PCRE2 is ASCII-only. You need to enable the UCP flag to get Unicode support.You mention Julia, and they've definitely had issues with PCRE2. For example, one thing that Rust's regex engine supports that PCRE2 doesn't is the ability to have Unicode features enabled while simultaneously searching possibly invalid UTF-8 without additional costly checks or undefined behavior. PCRE2 can't do that. See: https://lists.exim.org/lurker/message/20180412.091038.080cf6... and https://github.com/JuliaLang/julia/pull/26731
Also, maybe there should be a (2016) or even a (2004) in the title! (2016 is when this document was last revised, and 2004 is when it became a Unicode standard.)
https://docs.python.org/release/1.5.1/lib/module-regex.html
https://docs.python.org/2/whatsnew/2.5.html#new-improved-and...
>>> 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(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.)
Of course, it's probably a good idea to follow the sample syntax provided. :-)
- XML configuration for Windows DLL dependency
- CORBA aware DST Library
Oh boy! You're in luck today, you'll learn about side-by-side assemblies and application manifests: https://msdn.microsoft.com/en-us/library/windows/desktop/aa3...
[\p{letter} \p{decimal number}]
And compare for instance to the POSIX regexp character classes (a reference: https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basi...) [[:alpha:] [:digit:]]
Given that the Unicode standard goes much beyond, proper implementations should help to write regexps for the modern web, encountering problems we are typically faced with. It's a pity the standard goes not into detail there, thought (for instance, similiarity of characters).> [\p{letter} \p{decimal number}]
> And compare for instance to the POSIX regexp character classes
> [[:alpha:] [:digit:]]
No need for the future tense; Perl's had that at least since v5.12: http://perldoc.perl.org/5.12.0/perldelta.html#Unicode-overha... .