ICU
Describes how recheck checks a regular expression of the icu dialect.
Engine
recheck follows the syntax and the semantics of the regular expressions of ICU4C 79.1 (uregex_* and icu::RegexPattern), which Apple's NSRegularExpression, MySQL 8 and R's stringi use.
Settings
The icu dialect has no settings.
- CLI
- JavaScript
- Scala
$ recheck --dialect=icu '/^(a|a)*$/'
import { check } from "recheck";
await check("^(a|a)*$", "", { dialect: "icu" });
import codes.quine.labs.recheck.ReDoS
import codes.quine.labs.recheck.common.Parameters
import codes.quine.labs.resyntax.dialect.Dialect
ReDoS.check("^(a|a)*$", "", Parameters(dialect = Dialect.ICU))
Flags and Units
The matching unit is utf16-code-point (see Matching Units).
recheck supports the following flags of ICU, written as the letters of their inline flags.
| Flag | uregex flag | Inline | Notes |
|---|---|---|---|
d | UREGEX_UNIX_LINES | (?d) | Only \n is a line terminator for ., ^ and $ (not for \Z). |
i | UREGEX_CASE_INSENSITIVE | (?i) | A literal and a back-reference match the folding to several characters (e.g. ß matches "ss"). |
m | UREGEX_MULTILINE | (?m) | |
s | UREGEX_DOTALL | (?s) | . matches "\r\n" as one character. |
w | UREGEX_UWORD | (?w) | Not supported with \b and \B (see Syntax Limitations). |
x | UREGEX_COMMENTS | (?x) |
UREGEX_ERROR_ON_UNKNOWN_ESCAPES and UREGEX_LITERAL have no flag letter, so they cannot be given.
The inline flag (?u) has no effect, as in ICU.
Syntax Limitations
The following constructs are not supported, and they are reported as unsupported.
\band\Bwithw, which are the word boundaries of UAX #29 with ICU's dictionaries.\N{...}and the propertyName(e.g.\N{EM DASH}and\p{Name=EM DASH}), as in the other dialects having them.- The properties
Lead_Canonical_Combining_Class(lccc) andTrail_Canonical_Combining_Class(tccc) with a value.
recheck reports a range of a class to \h, \H, \v, \V, \p{...} or \P{...} (e.g. [a-\h]) as invalid, as a range to \w is in ICU, though ICU reads it as a range to the letter (e.g. [a-h]).
Approximations
- ICU tries the starts of a look-behind from the shortest, and
rechecktries them from the longest, as for Java. For example,(?<=(a|aa))bcaptures"a"of"aab"in ICU, but"aa"inrecheck. - Under
i, a run of literals matches the folding of the characters only at the boundaries of the literals (e.g.ffidoes not match"ffi", andsßdoes not match"ßs"). - In a class, escapes of a high and a low surrogate other than
\u(e.g.[\x{D83D}\x{DE00}]) are two characters inrecheck, but one surrogate pair in ICU. recheckdoes not reproduce the following behaviors of ICU.- A possessive repetition whose body matches the empty string overflows the backtrack stack (e.g.
(?:a?)*+bon"b"givesU_REGEX_STACK_OVERFLOW);recheckmatches it. findchooses the starts of a match taking a capture of a look-behind as empty, so(?<=(a))\1bdoes not match"aab";recheckmatches it.- Under
i, a class of one character matches as a literal, which matches the folding to several characters (e.g.(?i)[fi]matches"fi");rechecktakes it as a class. (?m)^matches between\rand\n, and(?dm)^matches at the end of the input after\n;rechecktakes"\r\n"as one line terminator for^as for$, and does not match^at the end of a non-empty input.- Under
i, a block withIn(e.g.\p{InLatin1Supplement}) does not match the case variants of its characters, unlike the other properties;recheckmatches them. - In a look-behind,
.withsreads\ralone before the end of the look-behind (e.g.(?s)\r(?<=.)matches"\r\n");recheckreads"\r\n"as one character there too. - An escape class or a property right after a
-or&between classes joins the class after the operator (e.g.[[ab]-[a]\w]matches nothing);recheckadds it after the operation ([b\w]). - A range after a
-or&that is a character (e.g.[a&-c]) begins at the character before them ([a&a-c]), and[&-c]is an error;recheckbegins it at the-or&(e.g.[a&-c]isaand the range from&toc).
- A possessive repetition whose body matches the empty string overflows the backtrack stack (e.g.
Runtime-Attack Verification
- Command:
c++ <file>.cpp -o <file> -licui18n -licuuc -licudataonce, and then the compiled program. - Matching:
uregex_findfrom the start, with ICU's default limits (no time limit, and a backtrack stack of 8,000,000 bytes). - Engine limits:
U_REGEX_TIME_OUT. - Engine errors:
U_REGEX_STACK_OVERFLOW,U_MEMORY_ALLOCATION_ERROR. - Environment variable:
RECHECK_ICU.
RECHECK_ICU replaces c++ with a command line of a C++ compiler, which finds ICU's headers and libraries.
recheck adds the program, -o, the compiled program and ICU's libraries after it.
For example, the following uses ICU of Homebrew.
$ export RECHECK_ICU="c++ -I$(brew --prefix icu4c@79)/include -L$(brew --prefix icu4c@79)/lib"
$ recheck --dialect=icu --runtime-attack-timeout=1s '/^(a|a)*$/'
recheck compiles the program once for each command line and version of the compiler, and the next runs reuse the compiled program.
ICU's libraries out of the default paths of the dynamic linker also need a run path that the libraries use too (e.g. -Wl,--disable-new-dtags,-rpath,/opt/icu/lib on Linux).
A failed compilation makes the runtime-attack verification fail with an unexpected error telling the output of the compiler.