RegularExpression re = new RegularExpression(regex);
if (re.matches(text)) { ... }
RegularExpression re = new RegularExpression(regex);
Match match = new Match();
if (re.matches(text, match)) {
... // You can refer captured texts with methods of the Match class.
}
RegularExpression re = new RegularExpression(regex, "i");
if (re.matches(text) >= 0) { ...}
You can specify options to RegularExpression(regex, options)
or setPattern(regex, options).
This options parameter consists of the following characters.
"i"
"m"
"s"
"u"
"w"
","
"X"
match() method does not do subsring matching
but entire string matching.
Differences from the Perl 5 regular expression
|
Meta characters are `. * + ? { [ ( ) | \ ^ $'.
This range matches the character.
This range matches a character which has a code point that is >= C1's code point and <= C2's code point. + *
...
These expressions specifies the same ranges as the following expressions.
Enumerated ranges are merged (union operation). [a-ec-z] is equivalent to [a-z]
Match instance
after matches(String,Match).
The 0th group means whole of this regular expression.
The Nth gorup is the inside of the Nth left parenthesis.
For instance, a regular expression is " *([^<:]*) +<([^>]*)> *" and target text is "From: TAMURA Kent <[email protected]>":
Match.getCapturedText(0):
" TAMURA Kent <[email protected]>"
Match.getCapturedText(1): "TAMURA Kent"
Match.getCapturedText(2): "[email protected]"
regex ::= ('(?' options ')')? term ('|' term)*
term ::= factor+
factor ::= anchors | atom (('*' | '+' | '?' | minmax ) '?'? )?
| '(?#' [^)]* ')'
minmax ::= '{' ([0-9]+ | [0-9]+ ',' | ',' [0-9]+ | [0-9]+ ',' [0-9]+) '}'
atom ::= char | '.' | char-class | '(' regex ')' | '(?:' regex ')' | '\' [0-9]
| '\w' | '\W' | '\d' | '\D' | '\s' | '\S' | category-block | '\X'
| '(?>' regex ')' | '(?' options ':' regex ')'
| '(?' ('(' [0-9] ')' | '(' anchors ')' | looks) term ('|' term)? ')'
options ::= [imsw]* ('-' [imsw]+)?
anchors ::= '^' | '$' | '\A' | '\Z' | '\z' | '\b' | '\B' | '\<' | '\>'
looks ::= '(?=' regex ')' | '(?!' regex ')'
| '(?<=' regex ')' | '(?<!' regex ')'
char ::= '\\' | '\' [efnrtv] | '\c' [@-_] | code-point | character-1
category-block ::= '\' [pP] category-symbol-1
| ('\p{' | '\P{') (category-symbol | block-name
| other-properties) '}'
category-symbol-1 ::= 'L' | 'M' | 'N' | 'Z' | 'C' | 'P' | 'S'
category-symbol ::= category-symbol-1 | 'Lu' | 'Ll' | 'Lt' | 'Lm' | Lo'
| 'Mn' | 'Me' | 'Mc' | 'Nd' | 'Nl' | 'No'
| 'Zs' | 'Zl' | 'Zp' | 'Cc' | 'Cf' | 'Cn' | 'Co' | 'Cs'
| 'Pd' | 'Ps' | 'Pe' | 'Pc' | 'Po'
| 'Sm' | 'Sc' | 'Sk' | 'So'
block-name ::= (See above)
other-properties ::= 'ALL' | 'ASSIGNED' | 'UNASSIGNED'
character-1 ::= (any character except meta-characters)
char-class ::= '[' ranges ']'
| '(?[' ranges ']' ([-+&] '[' ranges ']')? ')'
ranges ::= '^'? (range ','?)+
range ::= '\d' | '\w' | '\s' | '\D' | '\W' | '\S' | category-block
| range-char | range-char '-' range-char
range-char ::= '\[' | '\]' | '\\' | '\' [,-efnrtv] | code-point | character-2
code-point ::= '\x' hex-char hex-char
| '\x{' hex-char+ '}'
| '\v' hex-char hex-char hex-char hex-char hex-char hex-char
hex-char ::= [0-9a-fA-F]
character-2 ::= (any character except \[]-,)
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv abstract static class | |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final int | |
| pack-priv transient RegularExpression. | |
| pack-priv static final boolean | |
| pack-priv static final int | |
| pack-priv transient RangeToken | |
| pack-priv transient String | |
| pack-priv transient boolean | |
| pack-priv transient int | |
| pack-priv transient BMPattern | |
| pack-priv boolean | |
| pack-priv static final int | IGNORE_CASE
"i" |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv transient int | |
| pack-priv static final int | |
| pack-priv int | nofparen
The number of parenthesis in the regular expression. |
| pack-priv transient int | |
| pack-priv transient Op | |
| pack-priv int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv String | regex
A regular expression. |
| private static final long | |
| pack-priv static final int | SINGLE_LINE
"s" |
| pack-priv static final int | SPECIAL_COMMA
",". |
| pack-priv Token | tokentree
Internal representation of the regular expression. |
| pack-priv static final int | UNICODE_WORD_BOUNDARY
An option. |
| pack-priv static final int | USE_UNICODE_CATEGORY
This option redefines \d \D \w \W \s \S. |
| private static final int | |
| private static final int | |
| private static final int | |
| pack-priv static final int | XMLSCHEMA_MODE
"X". |
| Access | Constructor and Description |
|---|---|
| public | |
| public | RegularExpression(String
A regular expression regex, String A String consisted of "i" "m" "s" "u" "w" "," "X" options)Creates a new RegularExpression instance with options. |
| public | RegularExpression(String
A regular expression regex, String A String consisted of "i" "m" "s" "u" "w" "," "X" options, Locale locale)Creates a new RegularExpression instance with options. |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| private synchronized void | |
| private Op | |
| public boolean | equals(Object
the reference object with which to compare. obj)Overrides java. |
| pack-priv boolean | |
| public int | |
| public String | |
| public String | |
| private static final int | getPreviousWordType(RegularExpression.
|
| private static final int | |
| private static final int | |
| public int | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean | |
| private int | Returns: -1 when not match; offset of the end of matched string when match.
|
| pack-priv boolean | matchAnchor(RegularExpression.
|
| private boolean | |
| public boolean | Returns: true if the target is matched to this regular expression.Checks whether the target text contains this pattern or not. |
| public boolean | Returns: true if the target is matched to this regular expression.Start offset of the range. start, int End offset +1 of the range. end)Checks whether the target text contains this pattern in specified range or not. |
| public boolean | |
| public boolean | Returns: Offset of the start position in target; or -1 if not match.Start offset of the range. start, int End offset +1 of the range. end, Match A Match instance for storing matching result. match)Checks whether the target text contains this pattern in specified range or not. |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | Returns: Offset of the start position in target; or -1 if not match.Start offset of the range. start, int End offset +1 of the range. end, Match A Match instance for storing matching result. match)Checks whether the target text contains this pattern in specified range or not. |
| public boolean | Returns: true if the target is matched to this regular expression.Checks whether the target text contains this pattern or not. |
| public boolean | Returns: Offset of the start position in target; or -1 if not match.A Match instance for storing matching result. match)Checks whether the target text contains this pattern or not. |
| private static final boolean | |
| pack-priv void | |
| public void | |
| public void | |
| private void | |
| public void | |
| public void | |
| public String |