|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.xerces.impl.xpath.regex.RegularExpression
A regular expression matching engine using Non-deterministic Finite Automaton (NFA). This engine does not conform to the POSIX regular expression.
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 <kent@trl.ibm.co.jp>":
Match.getCapturedText(0)
:
" TAMURA Kent <kent@trl.ibm.co.jp>"
Match.getCapturedText(1)
: "TAMURA Kent"
Match.getCapturedText(2)
: "kent@trl.ibm.co.jp"
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 \[]-,)
Constructor Summary | |
RegularExpression(java.lang.String regex)
Creates a new RegularExpression instance. |
|
RegularExpression(java.lang.String regex,
java.lang.String options)
Creates a new RegularExpression instance with options. |
|
RegularExpression(java.lang.String regex,
java.lang.String options,
java.util.Locale locale)
Creates a new RegularExpression instance with options. |
|
RegularExpression(java.lang.String regex,
java.lang.String options,
java.util.Locale locale,
short datatypeXMLVersion)
|
Method Summary | |
boolean |
equals(java.lang.Object obj)
Return true if patterns are the same and the options are equivalent. |
int |
getNumberOfGroups()
Return the number of regular expression groups. |
java.lang.String |
getOptions()
Returns a option string. |
java.lang.String |
getPattern()
|
int |
hashCode()
|
boolean |
matches(char[] target)
Checks whether the target text contains this pattern or not. |
boolean |
matches(char[] target,
int start,
int end)
Checks whether the target text contains this pattern in specified range or not. |
boolean |
matches(char[] target,
int start,
int end,
Match match)
Checks whether the target text contains this pattern in specified range or not. |
boolean |
matches(char[] target,
Match match)
Checks whether the target text contains this pattern or not. |
boolean |
matches(java.text.CharacterIterator target)
Checks whether the target text contains this pattern or not. |
boolean |
matches(java.text.CharacterIterator target,
Match match)
Checks whether the target text contains this pattern or not. |
boolean |
matches(java.lang.String target)
Checks whether the target text contains this pattern or not. |
boolean |
matches(java.lang.String target,
int start,
int end)
Checks whether the target text contains this pattern in specified range or not. |
boolean |
matches(java.lang.String target,
int start,
int end,
Match match)
Checks whether the target text contains this pattern in specified range or not. |
boolean |
matches(java.lang.String target,
Match match)
Checks whether the target text contains this pattern or not. |
void |
setPattern(java.lang.String newPattern)
|
void |
setPattern(java.lang.String newPattern,
java.util.Locale locale)
|
void |
setPattern(java.lang.String newPattern,
java.lang.String options)
|
void |
setPattern(java.lang.String newPattern,
java.lang.String options,
java.util.Locale locale)
|
void |
setPattern(java.lang.String newPattern,
java.lang.String options,
java.util.Locale locale,
short datatypeXMLVersion)
|
java.lang.String |
toString()
Represents this instence in String. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public RegularExpression(java.lang.String regex) throws ParseException
regex
- A regular expression
org.apache.xerces.utils.regex.ParseException
- regex is not conforming to the syntax.
ParseException
public RegularExpression(java.lang.String regex, java.lang.String options) throws ParseException
regex
- A regular expressionoptions
- A String consisted of "i" "m" "s" "u" "w" "," "X"
org.apache.xerces.utils.regex.ParseException
- regex is not conforming to the syntax.
ParseException
public RegularExpression(java.lang.String regex, java.lang.String options, java.util.Locale locale) throws ParseException
regex
- A regular expressionoptions
- A String consisted of "i" "m" "s" "u" "w" "," "X"
org.apache.xerces.utils.regex.ParseException
- regex is not conforming to the syntax.
ParseException
public RegularExpression(java.lang.String regex, java.lang.String options, java.util.Locale locale, short datatypeXMLVersion)
Method Detail |
public boolean matches(char[] target)
public boolean matches(char[] target, int start, int end)
start
- Start offset of the range.end
- End offset +1 of the range.
public boolean matches(char[] target, Match match)
match
- A Match instance for storing matching result.
public boolean matches(char[] target, int start, int end, Match match)
start
- Start offset of the range.end
- End offset +1 of the range.match
- A Match instance for storing matching result.
public boolean matches(java.lang.String target)
public boolean matches(java.lang.String target, int start, int end)
start
- Start offset of the range.end
- End offset +1 of the range.
public boolean matches(java.lang.String target, Match match)
match
- A Match instance for storing matching result.
public boolean matches(java.lang.String target, int start, int end, Match match)
start
- Start offset of the range.end
- End offset +1 of the range.match
- A Match instance for storing matching result.
public boolean matches(java.text.CharacterIterator target)
public boolean matches(java.text.CharacterIterator target, Match match)
match
- A Match instance for storing matching result.
public void setPattern(java.lang.String newPattern) throws ParseException
ParseException
public void setPattern(java.lang.String newPattern, java.util.Locale locale) throws ParseException
ParseException
public void setPattern(java.lang.String newPattern, java.lang.String options) throws ParseException
ParseException
public void setPattern(java.lang.String newPattern, java.lang.String options, java.util.Locale locale) throws ParseException
ParseException
public void setPattern(java.lang.String newPattern, java.lang.String options, java.util.Locale locale, short datatypeXMLVersion) throws ParseException
ParseException
public java.lang.String getPattern()
public java.lang.String toString()
public java.lang.String getOptions()
setPattern()
.
RegularExpression(java.lang.String,java.lang.String)
,
setPattern(java.lang.String,java.lang.String)
public boolean equals(java.lang.Object obj)
public int hashCode()
public int getNumberOfGroups()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |