Class Regex
Builder and utility methods making it easier to construct and use
regular expressions. In addition, you can obtain a Matcher
with support for empty or null values
Empty and null values
Since 3.0.0, you can force null and empty strings
to be considered a positive match, regardless of the specified pattern.
To do so, set matchEmpty to true.
To have blank values (containing white spaces only) considered as
positive matches, also set trim to true.
When matching empties, doing replacement on a null value
behaves as if the value is an empty string.
- Since:
- 2.0.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConvenience flag that combinesPattern.UNICODE_CASEandPattern.CASE_INSENSITIVEstatic final intFlag that ignores diacritical marks when matching or replacing (e.g. accents). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancanonEq()comments()compile()Compiles a previously set pattern.Compiles the given pattern without assigning it to this object.static PatterncompileDotAll(String regex, boolean ignoreCase) Compiles a "dotall" pattern (dots match all, including new lines) with optional case sensitivity.createKeyValueExtractor(int keyGroup, int valueGroup) createKeyValueExtractor(String key, int valueGroup) dotAll()booleanstatic StringEscape special characters with a backslash (\) in a regular expression.getFlags()inthashCode()Ignores diacritical marks when matching or replacing (e.g. accents).booleanbooleanbooleanisDotAll()booleanbooleanbooleanbooleanGets whethernullor empty strings should be considered a positive match.booleanbooleanisTrim()Gets whether values should be trimmed before being evaluated (as perString.trim()).booleanbooleanbooleanliteral()Sets thatnullor empty strings should be considered a positive match.matcher(CharSequence text) Matches the previously set pattern against the given text.matcher(String pattern, CharSequence text) Matches the the given pattern against the given text without assigning the pattern to this object.setCanonEq(boolean canonEq) setComments(boolean comments) setDotAll(boolean dotAll) setFlags(int... flags) setIgnoreCase(boolean ignoreCase) setIgnoreDiacritic(boolean ignoreDiacritic) setLiteral(boolean literal) setMatchEmpty(boolean matchEmpty) Sets whethernullor empty strings should be considered a positive match.setMultiline(boolean multiline) setPattern(String pattern) setTrim(boolean trim) Sets whether values should be trimmed before being evaluated (as perString.trim()).setUnicodeCase(boolean unicode) setUnicodeCharacterClass(boolean unicode) setUnixLines(boolean unixLines) toString()trim()Sets that values should be trimmed before being evaluated (as perString.trim()).
-
Field Details
-
UNICODE_MARK_INSENSTIVE_FLAG
public static final int UNICODE_MARK_INSENSTIVE_FLAGFlag that ignores diacritical marks when matching or replacing (e.g. accents). This flag is not supported by JavaPatternand only works when used with this class.- See Also:
-
UNICODE_CASE_INSENSTIVE_FLAG
public static final int UNICODE_CASE_INSENSTIVE_FLAGConvenience flag that combinesPattern.UNICODE_CASEandPattern.CASE_INSENSITIVE- See Also:
-
-
Constructor Details
-
Regex
public Regex() -
Regex
-
Regex
-
-
Method Details
-
dotAll
-
setDotAll
-
isDotAll
public boolean isDotAll() -
ignoreCase
-
setIgnoreCase
-
isIgnoreCase
public boolean isIgnoreCase() -
unixLines
-
setUnixLines
-
isUnixLines
public boolean isUnixLines() -
literal
-
setLiteral
-
isLiteral
public boolean isLiteral() -
comments
-
setComments
-
isComments
public boolean isComments() -
multiline
-
setMultiline
-
isMultiline
public boolean isMultiline() -
canonEq
-
setCanonEq
-
isCanonEq
public boolean isCanonEq() -
unicodeCase
-
setUnicodeCase
-
isUnicodeCase
public boolean isUnicodeCase() -
unicodeCharacterClass
-
setUnicodeCharacterClass
-
isUnicodeCharacterClass
public boolean isUnicodeCharacterClass() -
ignoreDiacritic
Ignores diacritical marks when matching or replacing (e.g. accents).- Returns:
- this instance
-
setIgnoreDiacritic
-
isIgnoreDiacritic
public boolean isIgnoreDiacritic() -
isMatchEmpty
public boolean isMatchEmpty()Gets whethernullor empty strings should be considered a positive match.- Returns:
trueifnulland empty strings are considered a match- Since:
- 3.0.0
-
setMatchEmpty
Sets whethernullor empty strings should be considered a positive match. To also consider blank values as positive matches, usesetTrim(boolean).- Parameters:
matchEmpty-trueto havenulland empty strings are considered a match.- Returns:
- this instance
- Since:
- 3.0.0
-
matchEmpty
Sets thatnullor empty strings should be considered a positive match. Same as invokingsetMatchEmpty(boolean)withtrue.- Returns:
- this instance
- Since:
- 3.0.0
-
isTrim
public boolean isTrim()Gets whether values should be trimmed before being evaluated (as perString.trim()).- Returns:
trueif values are trimmed before evaluation- Since:
- 3.0.0
-
setTrim
Sets whether values should be trimmed before being evaluated (as perString.trim()).- Parameters:
trim-trueto trim values before evaluation- Returns:
- this instance
- Since:
- 3.0.0
-
trim
Sets that values should be trimmed before being evaluated (as perString.trim()). Same as invokingsetTrim(boolean)withtrue.- Returns:
- this instance
- Since:
- 3.0.0
-
setFlags
-
getFlags
-
setPattern
-
getPattern
-
compile
Compiles a previously set pattern.
For text-matching with diacritical mark insensitivity support enabled, or for
trim()andmatchEmpty()support, usematcher(CharSequence)instead.- Returns:
- compiled pattern
-
compile
Compiles the given pattern without assigning it to this object.
For text-matching with diacritical mark insensitivity support enabled, or for
trim()andmatchEmpty()support, usematcher(String, CharSequence)instead.- Parameters:
pattern- the pattern to compile- Returns:
- compiled pattern
- Throws:
IllegalArgumentException- if pattern isnull
-
compileDotAll
Compiles a "dotall" pattern (dots match all, including new lines) with optional case sensitivity.- Parameters:
regex- regular expressionignoreCase-trueto ignore character case.- Returns:
- compiled pattern
-
escape
Escape special characters with a backslash (\) in a regular expression. This is an alternative toPattern.quote(String)for when you do not want the string to be treated as a literal.- Parameters:
pattern- the pattern to escape- Returns:
- escaped pattern
-
matcher
Matches the previously set pattern against the given text.- Parameters:
text- the text to match- Returns:
- matcher
-
matcher
Matches the the given pattern against the given text without assigning the pattern to this object. Since 3.0.0,nullor empty text will generate no match unlessisMatchEmpty()istrue, in which case it will match positively.- Parameters:
pattern- the pattern to matchtext- the text to match- Returns:
- matcher
-
createKeyValueExtractor
-
createKeyValueExtractor
-
createKeyValueExtractor
-
createKeyValueExtractor
-
toString
-
equals
-
canEqual
-
hashCode
public int hashCode()
-