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 |
| 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. |
| 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. |
| 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 | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| 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.
|
| private int | Returns: -1 when not match; offset of the end of matched string when match.
|
| 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 | |
| private int | Returns: -1 when not match; offset of the end of matched string when match.
|
| pack-priv void | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean | |
| public void | |
| private void | |
| public void | |
| public String |
| CARRIAGE_RETURN | back to summary |
|---|---|
| pack-priv static final int CARRIAGE_RETURN | |
| context | back to summary |
|---|---|
| pack-priv transient RegularExpression. | |
| DEBUG | back to summary |
|---|---|
| pack-priv static final boolean DEBUG | |
| EXTENDED_COMMENT | back to summary |
|---|---|
| pack-priv static final int EXTENDED_COMMENT "x" | |
| firstChar | back to summary |
|---|---|
| pack-priv transient RangeToken firstChar | |
| fixedString | back to summary |
|---|---|
| pack-priv transient String fixedString | |
| fixedStringOnly | back to summary |
|---|---|
| pack-priv transient boolean fixedStringOnly | |
| fixedStringOptions | back to summary |
|---|---|
| pack-priv transient int fixedStringOptions | |
| fixedStringTable | back to summary |
|---|---|
| pack-priv transient BMPattern fixedStringTable | |
| hasBackReferences | back to summary |
|---|---|
| pack-priv boolean hasBackReferences | |
| IGNORE_CASE | back to summary |
|---|---|
| pack-priv static final int IGNORE_CASE "i" | |
| LINE_FEED | back to summary |
|---|---|
| pack-priv static final int LINE_FEED | |
| LINE_SEPARATOR | back to summary |
|---|---|
| pack-priv static final int LINE_SEPARATOR | |
| minlength | back to summary |
|---|---|
| pack-priv transient int minlength | |
| MULTIPLE_LINES | back to summary |
|---|---|
| pack-priv static final int MULTIPLE_LINES "m" | |
| nofparen | back to summary |
|---|---|
| pack-priv int nofparen The number of parenthesis in the regular expression. | |
| numberOfClosures | back to summary |
|---|---|
| pack-priv transient int numberOfClosures | |
| operations | back to summary |
|---|---|
| pack-priv transient Op operations | |
| options | back to summary |
|---|---|
| pack-priv int options | |
| PARAGRAPH_SEPARATOR | back to summary |
|---|---|
| pack-priv static final int PARAGRAPH_SEPARATOR | |
| PROHIBIT_FIXED_STRING_OPTIMIZATION | back to summary |
|---|---|
| pack-priv static final int PROHIBIT_FIXED_STRING_OPTIMIZATION "F" | |
| PROHIBIT_HEAD_CHARACTER_OPTIMIZATION | back to summary |
|---|---|
| pack-priv static final int PROHIBIT_HEAD_CHARACTER_OPTIMIZATION "H" | |
| regex | back to summary |
|---|---|
| pack-priv String regex A regular expression. | |
| SINGLE_LINE | back to summary |
|---|---|
| pack-priv static final int SINGLE_LINE "s" | |
| SPECIAL_COMMA | back to summary |
|---|---|
| pack-priv static final int SPECIAL_COMMA ",". | |
| tokentree | back to summary |
|---|---|
| pack-priv Token tokentree Internal representation of the regular expression. | |
| UNICODE_WORD_BOUNDARY | back to summary |
|---|---|
| pack-priv static final int UNICODE_WORD_BOUNDARY An option. This enables to process locale-independent word boundary for \b \B \< \>. By default, the engine considers a position between a word character (\w) and a non word character is a word boundary. By this option, the engine checks word boundaries with the method of 'Unicode Regular Expression Guidelines' Revision 4.
| |
| USE_UNICODE_CATEGORY | back to summary |
|---|---|
| pack-priv static final int USE_UNICODE_CATEGORY This option redefines \d \D \w \W \s \S. | |
| WT_IGNORE | back to summary |
|---|---|
| private static final int WT_IGNORE | |
| WT_LETTER | back to summary |
|---|---|
| private static final int WT_LETTER | |
| WT_OTHER | back to summary |
|---|---|
| private static final int WT_OTHER | |
| XMLSCHEMA_MODE | back to summary |
|---|---|
| pack-priv static final int XMLSCHEMA_MODE "X". XML Schema mode. | |
| RegularExpression | back to summary |
|---|---|
| public RegularExpression(String regex) throws ParseException Creates a new RegularExpression instance.
| |
| RegularExpression | back to summary |
|---|---|
| public RegularExpression(String regex, String options) throws ParseException Creates a new RegularExpression instance with options.
| |
| RegularExpression | back to summary |
|---|---|
| pack-priv RegularExpression(String regex, Token tok, int parens, boolean hasBackReferences, int options) | |
| compile | back to summary |
|---|---|
| private synchronized void compile(Token tok) Compiles a token tree into an operation flow. | |
| compile | back to summary |
|---|---|
| private Op compile(Token tok, Op next, boolean reverse) Converts a token to an operation. | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Return true if patterns are the same and the options are equivalent.
| |
| equals | back to summary |
|---|---|
| pack-priv boolean equals(String pattern, int options) | |
| getNumberOfGroups | back to summary |
|---|---|
| public int getNumberOfGroups() Return the number of regular expression groups. This method returns 1 when the regular expression has no capturing-parenthesis. | |
| getOptions | back to summary |
|---|---|
| public String getOptions() Returns a option string.
The order of letters in it may be different from a string specified
in a constructor or | |
| getPattern | back to summary |
|---|---|
| public String getPattern() | |
| getPreviousWordType | back to summary |
|---|---|
| private static final int getPreviousWordType(char[] target, int begin, int end, int offset, int opts) | |
| getPreviousWordType | back to summary |
|---|---|
| private static final int getPreviousWordType(String target, int begin, int end, int offset, int opts) | |
| getPreviousWordType | back to summary |
|---|---|
| private static final int getPreviousWordType(CharacterIterator target, int begin, int end, int offset, int opts) | |
| getWordType | back to summary |
|---|---|
| private static final int getWordType(char[] target, int begin, int end, int offset, int opts) | |
| getWordType | back to summary |
|---|---|
| private static final int getWordType(String target, int begin, int end, int offset, int opts) | |
| getWordType | back to summary |
|---|---|
| private static final int getWordType(CharacterIterator target, int begin, int end, int offset, int opts) | |
| getWordType0 | back to summary |
|---|---|
| private static final int getWordType0(char ch, int opts) | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| isEOLChar | back to summary |
|---|---|
| private static final boolean isEOLChar(int ch) | |
| isSet | back to summary |
|---|---|
| private static final boolean isSet(int options, int flag) | |
| isWordChar | back to summary |
|---|---|
| private static final boolean isWordChar(int ch) | |
| matchCharacterIterator | back to summary |
|---|---|
private int matchCharacterIterator(RegularExpression.
| |
| matchCharArray | back to summary |
|---|---|
private int matchCharArray(RegularExpression.
| |
| matches | back to summary |
|---|---|
| public boolean matches(char[] target) Checks whether the target text contains this pattern or not.
| |
| matches | back to summary |
|---|---|
| public boolean matches(char[] target, int start, int end) Checks whether the target text contains this pattern in specified range or not.
| |
| matches | back to summary |
|---|---|
| public boolean matches(char[] target, Match match) Checks whether the target text contains this pattern or not.
| |
| matches | back to summary |
|---|---|
| public boolean matches(char[] target, int start, int end, Match match) Checks whether the target text contains this pattern in specified range or not.
| |
| matches | back to summary |
|---|---|
| public boolean matches(String target) Checks whether the target text contains this pattern or not.
| |
| matches | back to summary |
|---|---|
| public boolean matches(String target, int start, int end) Checks whether the target text contains this pattern in specified range or not.
| |
| matches | back to summary |
|---|---|
| public boolean matches(String target, Match match) Checks whether the target text contains this pattern or not.
| |
| matches | back to summary |
|---|---|
| public boolean matches(String target, int start, int end, Match match) Checks whether the target text contains this pattern in specified range or not.
| |
| matches | back to summary |
|---|---|
| public boolean matches(CharacterIterator target) Checks whether the target text contains this pattern or not.
| |
| matches | back to summary |
|---|---|
| public boolean matches(CharacterIterator target, Match match) Checks whether the target text contains this pattern or not.
| |
| matchIgnoreCase | back to summary |
|---|---|
| private static final boolean matchIgnoreCase(int chardata, int ch) | |
| matchString | back to summary |
|---|---|
private int matchString(RegularExpression.
| |
| prepare | back to summary |
|---|---|
| pack-priv void prepare() Prepares for matching. This method is called just before starting matching. | |
| regionMatches | back to summary |
|---|---|
| private static final boolean regionMatches(char[] target, int offset, int limit, String part, int partlen) | |
| regionMatches | back to summary |
|---|---|
| private static final boolean regionMatches(char[] target, int offset, int limit, int offset2, int partlen) | |
| regionMatches | back to summary |
|---|---|
| private static final boolean regionMatches(String text, int offset, int limit, String part, int partlen) | |
| regionMatches | back to summary |
|---|---|
| private static final boolean regionMatches(String text, int offset, int limit, int offset2, int partlen) | |
| regionMatches | back to summary |
|---|---|
| private static final boolean regionMatches(CharacterIterator target, int offset, int limit, String part, int partlen) | |
| regionMatches | back to summary |
|---|---|
| private static final boolean regionMatches(CharacterIterator target, int offset, int limit, int offset2, int partlen) | |
| regionMatchesIgnoreCase | back to summary |
|---|---|
| private static final boolean regionMatchesIgnoreCase(char[] target, int offset, int limit, String part, int partlen) | |
| regionMatchesIgnoreCase | back to summary |
|---|---|
| private static final boolean regionMatchesIgnoreCase(char[] target, int offset, int limit, int offset2, int partlen) | |
| regionMatchesIgnoreCase | back to summary |
|---|---|
| private static final boolean regionMatchesIgnoreCase(String text, int offset, int limit, String part, int partlen) | |
| regionMatchesIgnoreCase | back to summary |
|---|---|
| private static final boolean regionMatchesIgnoreCase(String text, int offset, int limit, int offset2, int partlen) | |
| regionMatchesIgnoreCase | back to summary |
|---|---|
| private static final boolean regionMatchesIgnoreCase(CharacterIterator target, int offset, int limit, String part, int partlen) | |
| regionMatchesIgnoreCase | back to summary |
|---|---|
| private static final boolean regionMatchesIgnoreCase(CharacterIterator target, int offset, int limit, int offset2, int partlen) | |
| setPattern | back to summary |
|---|---|
| public void setPattern(String newPattern) throws ParseException | |
| setPattern | back to summary |
|---|---|
| private void setPattern(String newPattern, int options) throws ParseException | |
| setPattern | back to summary |
|---|---|
| public void setPattern(String newPattern, String options) throws ParseException | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Represents this instence in String.
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv char[] | |
| pack-priv CharacterIterator | |
| pack-priv boolean | |
| pack-priv int | |
| pack-priv int | |
| pack-priv Match | |
| pack-priv int[] | |
| pack-priv int | |
| pack-priv String |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| pack-priv void | |
| pack-priv void | |
| private void |
| charTarget | back to summary |
|---|---|
| pack-priv char[] charTarget | |
| ciTarget | back to summary |
|---|---|
| pack-priv CharacterIterator ciTarget | |
| inuse | back to summary |
|---|---|
| pack-priv boolean inuse | |
| length | back to summary |
|---|---|
| pack-priv int length | |
| limit | back to summary |
|---|---|
| pack-priv int limit | |
| match | back to summary |
|---|---|
| pack-priv Match match | |
| offsets | back to summary |
|---|---|
| pack-priv int[] offsets | |
| start | back to summary |
|---|---|
| pack-priv int start | |
| strTarget | back to summary |
|---|---|
| pack-priv String strTarget | |
| Context | back to summary |
|---|---|
| pack-priv Context() | |
| reset | back to summary |
|---|---|
| pack-priv void reset(CharacterIterator target, int start, int limit, int nofclosures) | |
| reset | back to summary |
|---|---|
| pack-priv void reset(String target, int start, int limit, int nofclosures) | |
| reset | back to summary |
|---|---|
| pack-priv void reset(char[] target, int start, int limit, int nofclosures) | |
| resetCommon | back to summary |
|---|---|
| private void resetCommon(int nofclosures) | |