@ThreadSafe public final class RegexECMA262Helper extends Object
ECMA 262 validation helper. A script engine is used instead of java.util.regex
because the latter doesn't comply with ECMA 262:
Pattern.DOTALL
;++
,
?+
, etc);\b
;
\<
(for beginning of word) and \>
(for end of word) are
not understood.And many, many other things. See here for the full story. And if you don't yet have Jeffrey Friedl's "Mastering regular expressions", just buy it :p
As script engine is used either Nashorn or Rhino as its fallback. Nashorn is only available on Java 8 runtimes or higher.
Rhino is only the fallback as it is tremendously slower.
Modifier and Type | Method and Description |
---|---|
static boolean |
regexIsValid(String regex)
Validate that a regex is correct
|
static boolean |
regMatch(String regex,
String input)
Matches an input against a given regex, in the real sense
of matching, that is, the regex can match anywhere in the input.
|
public static boolean regexIsValid(String regex)
regex
- the regex to validatepublic static boolean regMatch(String regex, String input)
Matches an input against a given regex, in the real sense
of matching, that is, the regex can match anywhere in the input. Java's
java.util.regex
makes the unfortunate mistake to make people
believe that matching is done on the whole input... Which is not true.
Also note that the regex MUST have been validated at this point
(using regexIsValid(String)
).
regex
- the regex to useinput
- the input to match against (and again, see description)