public final class Pattern extends Object implements 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(String regex)
Creates and returns a new
Pattern corresponding to
compiling regex with the default flags (0). |
static Pattern |
compile(String regex,
int flags)
Creates and returns a new
Pattern corresponding to
compiling regex with the default flags (0). |
int |
flags()
Returns the flags used in the constructor.
|
int |
groupCount()
Returns the number of capturing groups in this matcher's pattern.
|
Matcher |
matcher(CharSequence input)
Creates a new
Matcher matching the pattern against the input. |
boolean |
matches(String input) |
static boolean |
matches(String regex,
CharSequence input)
Matches a string against a regular expression.
|
String |
pattern()
Returns the pattern used in the constructor.
|
static String |
quote(String s)
Returns a literal pattern string for the specified
string.
|
void |
reset()
Releases memory used by internal caches associated with this pattern.
|
String[] |
split(String input)
Splits input around instances of the regular expression.
|
String[] |
split(String input,
int limit)
Splits input around instances of the regular expression.
|
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 String pattern()
public static Pattern compile(String regex)
Pattern corresponding to
compiling regex with the default flags (0).regex - the regular expressionPatternSyntaxException - if the pattern is malformedpublic static Pattern compile(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 MULTILINEPatternSyntaxException - if the regular expression is malformedIllegalArgumentException - if an unknown flag is givenpublic static boolean matches(String regex, CharSequence input)
regex - the regular expressioninput - the inputPatternSyntaxException - if the regular expression is malformedpublic boolean matches(String input)
public Matcher matcher(CharSequence input)
Matcher matching the pattern against the input.input - the input stringpublic String[] split(String input)
input - the input string to be splitpublic String[] split(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 String quote(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 int groupCount()
Copyright © 2015. All Rights Reserved.