public class Regex extends Object implements IXMLConfigurable
Builder and utility methods making it easier to construct and use regular expressions.
ignoreCase="[false|true]"
ignoreDiacritic="[false|true]"
dotAll="[false|true]"
unixLines="[false|true]"
literal="[false|true]"
comments="[false|true]"
multiline="[false|true]"
canonEq="[false|true]"
unicodeCase="[false|true]"
unicodeCharacterClass="[false|true]"
The above are configurable attributes consuming classes can expect.
The actual regular expression is expected to be the tag content.
Many of the available attributes on XML configuration represent the
regular expression flags as defined in Pattern
.
<sampleConfig
ignoreCase="true"
dotAll="true">
^start.*end$
</sampleConfig>
The above will match any text that starts with "start" and ends with "ends", regardless if there are new line characters in between.
Pattern
Modifier and Type | Field and Description |
---|---|
static int |
UNICODE_CASE_INSENSTIVE_FLAG
Convenience flag that combines
Pattern.UNICODE_CASE
and Pattern.CASE_INSENSITIVE |
static int |
UNICODE_MARK_INSENSTIVE_FLAG
Flag that ignores diacritical marks when matching or replacing
(e.g.
|
Constructor and Description |
---|
Regex() |
Regex(String pattern) |
Regex(String pattern,
int... flags) |
Modifier and Type | Method and Description |
---|---|
Regex |
canonEq() |
Regex |
comments() |
Pattern |
compile()
Compiles a previously set pattern.
|
Pattern |
compile(String pattern)
Compiles the given pattern without assigning it to this object.
|
static Pattern |
compileDotAll(String regex,
boolean ignoreCase)
Compiles a "dotall" pattern (dots match all, including new lines)
with optional case sensitivity.
|
RegexFieldValueExtractor |
createKeyValueExtractor() |
RegexFieldValueExtractor |
createKeyValueExtractor(int keyGroup,
int valueGroup) |
RegexFieldValueExtractor |
createKeyValueExtractor(String key) |
RegexFieldValueExtractor |
createKeyValueExtractor(String key,
int valueGroup) |
Regex |
dotAll() |
boolean |
equals(Object other) |
static String |
escape(String pattern)
Escape special characters with a backslash (\) in a regular expression.
|
Set<Integer> |
getFlags() |
String |
getPattern() |
int |
hashCode() |
Regex |
ignoreCase() |
Regex |
ignoreDiacritic()
Ignores diacritical marks when matching or replacing
(e.g.
|
boolean |
isCanonEq() |
boolean |
isComments() |
boolean |
isDotAll() |
boolean |
isIgnoreCase() |
boolean |
isIgnoreDiacritic() |
boolean |
isLiteral() |
boolean |
isMultiline() |
boolean |
isUnicodeCase() |
boolean |
isUnicodeCharacterClass() |
boolean |
isUnixLines() |
Regex |
literal() |
void |
loadFromXML(XML xml)
Load XML configuration values and initialized this object with them.
|
Matcher |
matcher(CharSequence text)
Matches the previously set pattern against the given text.
|
Matcher |
matcher(String pattern,
CharSequence text)
Matches the the given pattern against the given text without assigning
the pattern to this object.
|
Regex |
multiline() |
void |
saveToXML(XML xml)
Saves this object as XML.
|
Regex |
setCanonEq(boolean canonEq) |
Regex |
setComments(boolean comments) |
Regex |
setDotAll(boolean dotAll) |
void |
setFlags(int... flags) |
Regex |
setIgnoreCase(boolean ignoreCase) |
Regex |
setIgnoreDiacritic(boolean ignoreDiacritic) |
Regex |
setLiteral(boolean literal) |
Regex |
setMultiline(boolean multiline) |
Regex |
setPattern(String pattern) |
Regex |
setUnicodeCase(boolean unicode) |
Regex |
setUnicodeCharacterClass(boolean unicode) |
Regex |
setUnixLines(boolean unixLines) |
String |
toString() |
Regex |
unicodeCase() |
Regex |
unicodeCharacterClass() |
Regex |
unixLines() |
public static final int UNICODE_MARK_INSENSTIVE_FLAG
Pattern
and only
works when used with this class.public static final int UNICODE_CASE_INSENSTIVE_FLAG
Pattern.UNICODE_CASE
and Pattern.CASE_INSENSITIVE
public Regex()
public Regex(String pattern)
public Regex(String pattern, int... flags)
public Regex dotAll()
public Regex setDotAll(boolean dotAll)
public boolean isDotAll()
public Regex ignoreCase()
public Regex setIgnoreCase(boolean ignoreCase)
public boolean isIgnoreCase()
public Regex unixLines()
public Regex setUnixLines(boolean unixLines)
public boolean isUnixLines()
public Regex literal()
public Regex setLiteral(boolean literal)
public boolean isLiteral()
public Regex comments()
public Regex setComments(boolean comments)
public boolean isComments()
public Regex multiline()
public Regex setMultiline(boolean multiline)
public boolean isMultiline()
public Regex canonEq()
public Regex setCanonEq(boolean canonEq)
public boolean isCanonEq()
public Regex unicodeCase()
public Regex setUnicodeCase(boolean unicode)
public boolean isUnicodeCase()
public Regex unicodeCharacterClass()
public Regex setUnicodeCharacterClass(boolean unicode)
public boolean isUnicodeCharacterClass()
public Regex ignoreDiacritic()
public Regex setIgnoreDiacritic(boolean ignoreDiacritic)
public boolean isIgnoreDiacritic()
public void setFlags(int... flags)
public String getPattern()
public Pattern compile()
Compiles a previously set pattern.
For text-matching with diacritical mark insensitivity support enabled,
use matcher(CharSequence)
instead.
public Pattern compile(String pattern)
Compiles the given pattern without assigning it to this object.
For text-matching with diacritical mark insensitivity support enabled,
use matcher(String, CharSequence)
instead.
pattern
- the pattern to compilepublic static Pattern compileDotAll(String regex, boolean ignoreCase)
regex
- regular expressionignoreCase
- true
to ignore character case.public static String escape(String pattern)
Pattern.quote(String)
for when you do not want the string
to be treated as a literal.pattern
- the pattern to escapepublic Matcher matcher(CharSequence text)
text
- the text to matchpublic Matcher matcher(String pattern, CharSequence text)
pattern
- the pattern to matchtext
- the text to matchpublic RegexFieldValueExtractor createKeyValueExtractor()
public RegexFieldValueExtractor createKeyValueExtractor(String key)
public RegexFieldValueExtractor createKeyValueExtractor(String key, int valueGroup)
public RegexFieldValueExtractor createKeyValueExtractor(int keyGroup, int valueGroup)
public void loadFromXML(XML xml)
IXMLConfigurable
loadFromXML
in interface IXMLConfigurable
xml
- the XML to load into this objectpublic void saveToXML(XML xml)
IXMLConfigurable
saveToXML
in interface IXMLConfigurable
xml
- the XML that will representing this objectCopyright © 2008–2023 Norconex Inc.. All rights reserved.