.NET
Describes how recheck checks a regular expression of the dotnet dialect.
Engine
recheck follows the syntax and the semantics of .NET 11's System.Text.RegularExpressions.Regex.
Settings
The dotnet dialect has no settings.
- CLI
- JavaScript
- Scala
$ recheck --dialect=dotnet '/^(a|a)*$/'
import { check } from "recheck";
await check("^(a|a)*$", "", { dialect: "dotnet" });
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.DotNet))
Flags and Units
The matching unit is utf16 (see Matching Units).
recheck supports the following RegexOptions, written as the letters of their inline options.
An option without an inline option has a letter of recheck's own.
| Flag | RegexOptions | Inline | Notes |
|---|---|---|---|
e | ECMAScript | ECMAScript-compliant behavior (see below). An error with l, n, s or x. | |
i | IgnoreCase | (?i) | In the invariant culture. |
l | AnyNewLine | ^, $, \Z and . see \r\n, \n, \v, \f, \r, U+0085, U+2028 and U+2029 as line terminators. An error with e. | |
m | Multiline | (?m) | |
n | ExplicitCapture | (?n) | |
s | Singleline | (?s) | |
x | IgnorePatternWhitespace | (?x) |
e makes the following differences, as .NET's ECMAScript does.
\d,\sand\ware[0-9],[\t\n\v\f\r ]and[0-9A-Z_a-zİ], and\band\Bsee the characters of\was word characters. In a class,icloses them as the other characters (e.g.[\W]matchesk, since U+212A KELVIN SIGN is not in\w).- An unknown escape is the character (e.g.
\qisq). \Nis a back-reference by the most digits that make the number of a group opened before it, followed by the rest of the digits (e.g.(a)\10is\1and0, and\2of(?<n>a)\2(b)is a back-reference ton, the second group by .NET's numbering). Without such a group, it is an octal escape below\400or the digit (e.g.\1(a)is U+0001, and\8is8).- A back-reference to an unset group matches the empty string.
[^]matches any character, while[]still starts a class with].
Syntax Limitations
The following constructs are not supported, and they are reported as unsupported.
- Balancing groups (e.g.
(?<close-open>...)). - Internal property names (e.g.
\p{_xmlI}).
The RegexOptions RightToLeft and NonBacktracking have no flag letter, so they cannot be given.
Approximations
- With
e, .NET drops the digits after a back-reference\Nwhile the number is not above the largest group number plus one (e.g.\13after twelve groups is\1without3), whichrecheckdoes not reproduce: it reads the rest of the digits as characters, as .NET's documentation says. \Gmatches only at the start of the input, sincerecheckmodels a search from there, not one from a later position (e.g.Match.NextMatch).- Case-insensitive matching follows the invariant culture, not the current culture (e.g.
(?i)idoes not matchİas it does in the Turkish culture).
Optimizations
recheck does not implement the optimizations specific to .NET, so an attack that recheck reports may not work on .NET, and the runtime-attack verification checks whether it does.
Runtime-Attack Verification
- Command:
dotnet build <file>.cs -o <dir> --disable-build-serversonce, and thendotnet <dir>/<file>.dll. - Matching:
Regex.Match. - Engine limits: none.
- Engine errors:
OutOfMemoryException,InsufficientExecutionStackException. - Environment variable:
RECHECK_DOTNET.
dotnet builds the program as a file-based app, which needs a .NET 11 SDK or later for RegexOptions.AnyNewLine.
RECHECK_DOTNET replaces dotnet in both commands.
dotnet builds it with the latest SDK installed, since global.json in the current directory does not apply.
recheck builds the program once for each command line and set of the SDKs and the runtimes that dotnet lists, and the next runs reuse the build.