public final class RegexEquivalents extends Object
java.util.regex replaceAll, in one linear pass.
The regexes they replace backtrack over a long run that does not end where the pattern needs it to, which made them
quadratic on long input.
Whitespace here is the regex \s of Java 8 without UNICODE_CHARACTER_CLASS: space, tab, line
feed, vertical tab, form feed and carriage return. A pattern ending in $ (without MULTILINE) also
matches before a line terminator that ends the input: \n, \r\n, \r,
,
or .
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isRegexWhitespace(char c)
A character of the regex
\s. |
static String |
removeWhitespace(String s)
s.replaceAll("\\s+", ""). |
static String |
stripLeadingWhitespace(String s)
s.replaceAll("^\\s+", ""). |
static String |
stripTrailingSemicolons(String s)
s.replaceAll(";+$", ""). |
static String |
stripTrailingWhitespace(String s)
s.replaceAll("\\s+$", ""). |
public static boolean isRegexWhitespace(char c)
\s.public static String removeWhitespace(String s)
s.replaceAll("\\s+", "").public static String stripLeadingWhitespace(String s)
s.replaceAll("^\\s+", "").public static String stripTrailingWhitespace(String s)
s.replaceAll("\\s+$", "").public static String stripTrailingSemicolons(String s)
s.replaceAll(";+$", "").