public final class Pattern
extends java.lang.Object
implements java.io.Serializable
java.util.regex.Pattern
API.
The matching functions take String
arguments instead of the more general Java
CharSequence
since the latter doesn't provide UTF-16 decoding.
See the package-level documentation for an overview of how to use this API.
Modifier and Type | Field and Description |
---|---|
static int |
CASE_INSENSITIVE
Flag: case insensitive matching.
|
static int |
DISABLE_UNICODE_GROUPS
Flag: Unicode groups (e.g.
|
static int |
DOTALL
Flag: dot (
. ) matches all characters, including newline. |
static int |
MULTILINE
Flag: multiline matching:
^ and $ match at beginning and end of line, not just
beginning and end of input. |
Modifier and Type | Method and Description |
---|---|
static Pattern |
compile(java.lang.String regex)
Creates and returns a new
Pattern corresponding to compiling regex with the
default flags (0). |
static Pattern |
compile(java.lang.String regex,
int flags)
Creates and returns a new
Pattern corresponding to compiling regex with the
default flags (0). |
boolean |
equals(java.lang.Object o) |
int |
flags()
Returns the flags used in the constructor.
|
int |
groupCount()
Returns the number of capturing groups in this matcher's pattern.
|
int |
hashCode() |
Matcher |
matcher(java.lang.CharSequence input)
Creates a new
Matcher matching the pattern against the input. |
boolean |
matches(java.lang.String input) |
static boolean |
matches(java.lang.String regex,
java.lang.CharSequence input)
Matches a string against a regular expression.
|
java.lang.String |
pattern()
Returns the pattern used in the constructor.
|
static java.lang.String |
quote(java.lang.String s)
Returns a literal pattern string for the specified string.
|
void |
reset()
Releases memory used by internal caches associated with this pattern.
|
java.lang.String[] |
split(java.lang.String input)
Splits input around instances of the regular expression.
|
java.lang.String[] |
split(java.lang.String input,
int limit)
Splits input around instances of the regular expression.
|
java.lang.String |
toString() |
public static final int CASE_INSENSITIVE
public static final int DOTALL
.
) matches all characters, including newline.public static final int MULTILINE
^
and $
match at beginning and end of line, not just
beginning and end of input.public static final int DISABLE_UNICODE_GROUPS
\p\ Greek\
) will be syntax errors.public void reset()
public int flags()
public java.lang.String pattern()
public static Pattern compile(java.lang.String regex)
Pattern
corresponding to compiling regex
with the
default flags (0).regex
- the regular expressionPatternSyntaxException
- if the pattern is malformedpublic static Pattern compile(java.lang.String regex, int flags)
Pattern
corresponding to compiling regex
with the
default flags (0).regex
- the regular expressionflags
- bitwise OR of the flag constants CASE_INSENSITIVE
, DOTALL
, and
MULTILINE
PatternSyntaxException
- if the regular expression is malformedjava.lang.IllegalArgumentException
- if an unknown flag is givenpublic static boolean matches(java.lang.String regex, java.lang.CharSequence input)
regex
- the regular expressioninput
- the inputPatternSyntaxException
- if the regular expression is malformedpublic boolean matches(java.lang.String input)
public Matcher matcher(java.lang.CharSequence input)
Matcher
matching the pattern against the input.input
- the input stringpublic java.lang.String[] split(java.lang.String input)
input
- the input string to be splitpublic java.lang.String[] split(java.lang.String input, int limit)
If limit <= 0
, there is no limit on the size of the returned array. If
limit == 0
, empty strings that would occur at the end of the array are omitted. If
limit > 0
, at most limit strings are returned. The final string contains the remainder
of the input, possibly including additional matches of the pattern.
input
- the input string to be splitlimit
- the limitpublic static java.lang.String quote(java.lang.String s)
This method produces a string that can be used to create a Pattern
that would
match the string s
as if it were a literal pattern.
s
- The string to be literalizedpublic java.lang.String toString()
toString
in class java.lang.Object
public int groupCount()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object