java.lang.Object
org.seppiko.commons.utils.RegexUtil
Regular expression utility
- Author:
- Leonard Woo
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringfind(String regex, CharSequence input) Returns the input subsequence captured by the given index during match operation.static MatchergetMatcher(String regex, CharSequence input) A matcher that will match the given input against this pattern.static PatterngetPattern(String regex) Compiles the given regular expression the given input against it.static booleanmatches(String regex, CharSequence input) Compiles the given regular expression and attempts to match the given input against it.static String[]split(String regex, CharSequence input) Returns the input subsequence split by the given expression in a string array.
-
Method Details
-
matches
Compiles the given regular expression and attempts to match the given input against it.- Parameters:
regex- The expression to be compiled.input- The character sequence to be matched.- Returns:
- Whether the regular expression matches on the input.
-
find
Returns the input subsequence captured by the given index during match operation.- Parameters:
regex- The expression to be compiled.input- The character sequence to be matched.- Returns:
- The (possibly empty) subsequence captured by the index during match, or empty if the group failed to match part of the input.
-
split
Returns the input subsequence split by the given expression in a string array.- Parameters:
regex- The delimiting regular expression.input- The character sequence to be split.- Returns:
- The array of strings computed by splitting the input around matches of this pattern. If the expression's syntax is invalid return an empty string array.
-
getMatcher
public static Matcher getMatcher(String regex, CharSequence input) throws NullPointerException, IllegalArgumentException A matcher that will match the given input against this pattern.- Parameters:
regex- The expression to be compiled.input- The character sequence to be matched.- Returns:
Matcherinstance.- Throws:
NullPointerException- If regex or input isnull.IllegalArgumentException- if the expression's syntax is invalid.
-
getPattern
Compiles the given regular expression the given input against it.- Parameters:
regex- The expression to be compiled.- Returns:
PatternThe given regular expression compiled into a pattern.- Throws:
PatternSyntaxException- If the expression's syntax is invalid.NullPointerException- If regex isnull.
-