Expand description
java.util.regex match and replacement semantics over the regex crate.
Kafka’s principal-mapping rules, sasl.kerberos.principal.to.local.rules
and ssl.principal.mapping.rules, are Java regular expressions applied
with Matcher.matches(), Matcher.replaceAll and Matcher.replaceFirst.
The regex crate differs from Java in the three places those rules touch:
-
Whole-input match.
Matcher.matches()succeeds when some match of the pattern spans the whole input, found by backtracking. A leftmost-firstfindthat happens to stop short, asa|abdoes onab, is not the same test.JavaPattern::matchesruns a separately compiled\A(?:pattern)\z. -
Group references in the replacement. Java reads
$then one digit, and extends the number digit by digit only while the result is still a group of the pattern, so$1_$2is group 1,_, group 2 and$12with one group is group 1 then2. Theregexcrate takes the longest[_0-9A-Za-z]run as the group name and expands an unknown group to nothing. A backslash escapes the next character, and malformed references are errors rather than empty text. -
Empty matches during
replaceAll. Java retries one character past an empty match and allows an empty match right after a non-empty one, sox*overxxwith[$0]is[xx][]. -
Predefined classes. Without
UNICODE_CHARACTER_CLASS, Java’s\d,\w,\sand\bare ASCII-only; theregexcrate’s are Unicode.JavaPattern::newrewrites them to their ASCII forms. It also makes any escaped non-alphanumeric character a literal, as Java does, where theregexcrate rejects an escaped,or@.
Otherwise the pattern dialect is the regex crate’s: constructs it does
not support, such as back-references and look-around, fail to compile.
Structs§
- Java
Pattern - A pattern compiled for Java’s
matches,replaceAllandreplaceFirst.
Enums§
- Java
Replacement Error - Why a Java replacement string could not be expanded against a match.