A handle for a precompiled regular expression.
To match a regular expression
myExpr
against a text
myString
one should first create a Pattern object:
Pattern p=new Pattern(myExpr);
then obtain a Matcher object:
Matcher matcher=p.matcher(myText);
The latter is an automaton that actually performs a search. It provides the following methods:
search for matching substrings : matcher.find() or matcher.findAll(); test whether the text matches the whole pattern : matcher.matches(); test whether the text matches the beginning of the pattern : matcher.matchesPrefix(); search with custom options : matcher.find(int options) Flags
Flags (see REFlags interface) change the meaning of some regular expression elements at compiletime. These flags may be passed both as string(see Pattern(String,String)) and as bitwise OR of:
REFlags.IGNORE_CASE - enables case insensitivity REFlags.MULTILINE - forces "^" and "$" to match both at the start and the end of line; REFlags.DOTALL - forces "." to match eols('\r' and '\n' in ASCII); REFlags.IGNORE_SPACES - literal spaces in expression are ignored for better readability; REFlags.UNICODE - the predefined classes('\w','\d',etc) are referenced to Unicode; REFlags.XML_SCHEMA - permits XML Schema regular expressions syntax extentions. Multithreading
Pattern instances are thread-safe, i.e. the same Pattern object may be used by any number of threads simultaniously. On the other hand, the Matcher objects are NOT thread safe, so, given a Pattern instance, each thread must obtain and use its own Matcher.
@see REFlags
@see Matcher
@see Matcher#setTarget(java.lang.String)
@see Matcher#setTarget(java.lang.String,int,int)
@see Matcher#setTarget(char[],int,int)
@see Matcher#setTarget(java.io.Reader,int)
@see MatchResult
@see MatchResult#group(int)
@see MatchResult#start(int)
@see MatchResult#end(int)
@see MatchResult#length(int)
@see MatchResult#charAt(int,int)
@see MatchResult#prefix()
@see MatchResult#suffix()