If you do not need Unicode support you can build PCRE2 without it, in which case the library will be smaller. . .
In UTF modes, repeat quantifiers apply to complete UTF characters, not to individual code units.
In UTF modes, the dot metacharacter matches one UTF character instead of a single code unit.
The escape sequence \eC can be used to match a single code unit in a UTF mode,
but its use can lead to some strange effects because it breaks up multi-unit
characters (see the description of \eC in the
HREF
pcre2pattern
documentation).
The use of \eC is not supported by the alternative matching function pcre2_dfa_match() when in UTF-8 or UTF-16 mode, that is, when a character may consist of more than one code unit. The use of \eC in these modes provokes a match-time error. Also, the JIT optimization does not support \eC in these modes. If JIT optimization is requested for a UTF-8 or UTF-16 pattern that contains \eC, it will not succeed, and so when pcre2_match() is called, the matching will be carried out by the normal interpretive function.
The character escapes \eb, \eB, \ed, \eD, \es, \eS, \ew, and \eW correctly test
characters of any code value, but, by default, the characters that PCRE2
recognizes as digits, spaces, or word characters remain the same set as in
non-UTF mode, all with code points less than 256. This remains true even when
PCRE2 is built to include Unicode support, because to do otherwise would slow
down matching in many common cases. Note that this also applies to \eb
and \eB, because they are defined in terms of \ew and \eW. If you want
to test for a wider sense of, say, "digit", you can use explicit Unicode
property tests such as \ep{Nd}. Alternatively, if you set the PCRE2_UCP option,
the way that the character escapes work is changed so that Unicode properties
are used to determine which characters match. There are more details in the
section on
HTML <a href="pcre2pattern.html#genericchartypes">
</a>
generic character types
in the
HREF
pcre2pattern
documentation.
Similarly, characters that match the POSIX named character classes are all low-valued characters, unless the PCRE2_UCP option is set.
However, the special horizontal and vertical white space matching escapes (\eh, \eH, \ev, and \eV) do match all the appropriate Unicode characters, whether or not PCRE2_UCP is set.
Case-insensitive matching in UTF mode makes use of Unicode properties. A few Unicode characters such as Greek sigma have more than two codepoints that are case-equivalent, and these are treated as such. . .
UTF-16 and UTF-32 strings can indicate their endianness by special code knows as a byte-order mark (BOM). The PCRE2 functions do not handle this, expecting strings to be in host byte order.
A UTF string is checked before any other processing takes place. In the case of pcre2_match() and pcre2_dfa_match() calls with a non-zero starting offset, the check is applied only to that part of the subject that could be inspected during matching, and there is a check that the starting offset points to the first code unit of a character or to the end of the subject. If there are no lookbehind assertions in the pattern, the check starts at the starting offset. Otherwise, it starts at the length of the longest lookbehind before the starting offset, or at the start of the subject if there are not that many characters before the starting offset. Note that the sequences \eb and \eB are one-character lookbehinds.
In addition to checking the format of the string, there is a check to ensure that all code points lie in the range U+0 to U+10FFFF, excluding the surrogate area. The so-called "non-character" code points are not excluded because Unicode corrigendum #9 makes it clear that they should not be.
Characters in the "Surrogate Area" of Unicode are reserved for use by UTF-16, where they are used in pairs to encode code points with values greater than 0xFFFF. The code points that are encoded by UTF-16 pairs are available independently in the UTF-8 and UTF-32 encodings. (In other words, the whole surrogate thing is a fudge for UTF-16 which unfortunately messes up UTF-8 and UTF-32.)
In some situations, you may already know that your strings are valid, and therefore want to skip these checks in order to improve performance, for example in the case of a long subject string that is being scanned repeatedly. If you set the PCRE2_NO_UTF_CHECK option at compile time or at match time, PCRE2 assumes that the pattern or subject it is given (respectively) contains only valid UTF code unit sequences.
Passing PCRE2_NO_UTF_CHECK to pcre2_compile() just disables the check for the pattern; it does not also apply to subject strings. If you want to disable the check for a subject string you must pass this option to pcre2_match() or pcre2_dfa_match().
If you pass an invalid UTF string when PCRE2_NO_UTF_CHECK is set, the result
is undefined and your program may crash or loop indefinitely.
.
.
HTML <a name="utf8strings"></a>
Philip Hazel University Computing Service Cambridge, England.. .
Last updated: 03 July 2016 Copyright (c) 1997-2016 University of Cambridge.