Java Reference
In-Depth Information
System
.
out
.
println
(
"'"
+
pattern
+
"'"
+
(
found
?
" matches '"
:
" doesn't match '"
) +
in
+
"'"
);
}
}
}
The
java.util.regex
package consists of two classes,
Pattern
and
Matcher
, which
provide the public API shown in
Example 4-1
.
Example 4-1. Regex public API
/** The main public API of the java.util.regex package.
* Prepared by javap and Ian Darwin.
*/
package
package
java
.
util
.
regex
;
public
public final
Pattern
{
// Flags values ('or' together)
public
final class
class
Pattern
public static
int
UNIX_LINES
,
CASE_INSENSITIVE
,
COMMENTS
,
MULTILINE
,
DOTALL
,
UNICODE_CASE
,
CANON_EQ
;
// No public constructors; use these Factory methods
public
static final
final
int
public static
static
Pattern
compile
(
String patt
);
public
public static
int
flags
);
// Method to get a Matcher for this Pattern
public
static
Pattern
compile
(
String patt
,
int
public
Matcher
matcher
(
CharSequence input
);
// Information methods
public
public
String
pattern
();
public
public
int
int
flags
();
// Convenience methods
public
public static
static
boolean
boolean
matches
(
String pattern
,
CharSequence input
);
public
public
String
[]
split
(
CharSequence input
);
public
public
String
[]
split
(
CharSequence input
,
int
int
max
);
}
public
public final
Matcher
{
// Action: find or match methods
public
final class
class
Matcher
public
boolean
boolean
matches
();
public
public
boolean
boolean
find
();
public
public
boolean
boolean
find
(
int
int
start
);
public
public
boolean
boolean
lookingAt
();
// "Information about the previous match" methods
public
public
int
int
start
();