Regular expressions must be encoded as string literals and follow the string quoting rules. For example, the regular expression \A is represented in KQL as "\\A". The extra backslash indicates that the other backslash is part of the regular expression \A.
Nested/grouping class (matching any character except y and z)
[a-y&&xyz]
Intersection (matching x or y)
[0-9&&[^4]]
Subtraction using intersection and negation (matching 0-9 except 4)
[0-9--4]
Direct subtraction (matching 0-9 except 4)
[a-g~~b-h]
Symmetric difference (matching a and h only)
[\[\]]
Escape in character classes (matching [ or ])
Any named character class may appear inside a bracketed [...] character class.
For example, [\p{Greek}[:digit:]] matches any ASCII digit or any codepoint in the Greek script.
Unicode affects memory and speed: Unicode character classes like \w match ~140,000 codepoints. If ASCII suffices, use [0-9A-Za-z_] or (?-u:\w) instead.
Word boundaries: If you don't need Unicode-aware word boundaries, (?-u:\b) is faster than \b.
Literals accelerate searches: Including literal characters in your pattern helps the regex engine optimize. For example, in \w+@\w+, the @ is matched first, then a reverse match finds the start.