public class Pattern extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
static int |
CANON_EQ
|
static int |
CASE_INSENSITIVE
|
static int |
COMMENTS
|
static int |
DOTALL
|
static int |
LITERAL
|
static int |
MULTILINE
|
static int |
UNICODE_CASE
|
static int |
UNIX_LINES
|
Modifier | Constructor and Description |
---|---|
protected |
Pattern(String regex,
int flags)
Constructs a named pattern with the given regular expression and flags
|
Modifier and Type | Method and Description |
---|---|
static Pattern |
compile(String regex)
Compiles the given regular expression into a pattern
|
static Pattern |
compile(String regex,
int flags)
Compiles the given regular expression into a pattern with the given flags
|
boolean |
equals(Object obj) |
static Map<String,List<GroupInfo>> |
extractGroupInfo(String namedPattern)
Parses info on named capture groups from a pattern
|
int |
flags()
Returns this pattern's match flags
|
Map<String,List<GroupInfo>> |
groupInfo()
Gets the names and group info (group index and string position
within the named pattern) of all named capture groups
|
List<String> |
groupNames()
Gets the names of all capture groups
|
int |
hashCode() |
int |
indexOf(String groupName)
Gets the group index of a named capture group
|
int |
indexOf(String groupName,
int index)
Gets the group index of a named capture group at the
specified index.
|
Matcher |
matcher(CharSequence input)
Creates a matcher that will match the given input against this pattern.
|
String |
namedPattern()
Returns the original regular expression (including named groups)
|
Pattern |
pattern()
Returns the wrapped
Pattern |
String |
replaceProperties(String replacementPattern)
Replaces group-name properties (e.g.,
${named} ) in
a replacement pattern with the equivalent reference that uses the
corresponding group index (e.g., $2 ). |
String[] |
split(CharSequence input)
Splits the given input sequence around matches of this pattern.
|
String[] |
split(CharSequence input,
int limit)
Splits the given input sequence around matches of this pattern.
|
String |
standardPattern()
Returns the regular expression from which this pattern was compiled.
|
String |
toString()
Returns a string representation of this pattern
|
public static final int UNIX_LINES
public static final int CASE_INSENSITIVE
public static final int COMMENTS
public static final int MULTILINE
public static final int LITERAL
public static final int DOTALL
public static final int UNICODE_CASE
public static final int CANON_EQ
protected Pattern(String regex, int flags)
regex
- the expression to be compiledflags
- Match flags, a bit mask that may include:
public static Pattern compile(String regex)
regex
- the expression to be compiledpublic static Pattern compile(String regex, int flags)
regex
- the expression to be compiledflags
- Match flags, a bit mask that may include:
public int indexOf(String groupName)
groupName
- name of capture grouppublic int indexOf(String groupName, int index)
groupName
- name of capture groupindex
- the instance index of the named capture group within
the pattern; e.g., index is 2 for the third instanceIndexOutOfBoundsException
- if instance index is out of boundspublic int flags()
public Matcher matcher(CharSequence input)
input
- The character sequence to be matchedpublic String standardPattern()
public String namedPattern()
public List<String> groupNames()
public Map<String,List<GroupInfo>> groupInfo()
public String replaceProperties(String replacementPattern)
${named}
) in
a replacement pattern with the equivalent reference that uses the
corresponding group index (e.g., $2
). If the string
contains literal "$", it must be escaped with slash or else this call
will attempt to parse it as a group-name property.
This is meant to be used to transform the parameter for:
replacementPattern
- the input string to be evaluatedPatternSyntaxException
- group name was not foundpublic String[] split(CharSequence input, int limit)
The array returned by this method contains each substring of the input sequence that is terminated by another subsequence that matches this pattern or is terminated by the end of the input sequence. The substrings in the array are in the order in which they occur in the input. If this pattern does not match any subsequence of the input then the resulting array has just one element, namely the input sequence in string form.
The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n - 1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.
input
- The character sequence to be splitlimit
- The result threshold, as described abovepublic String[] split(CharSequence input)
input
- The character sequence to be splitpublic String toString()
public static Map<String,List<GroupInfo>> extractGroupInfo(String namedPattern)
namedPattern
- regex the regular expression pattern to parseCopyright © 2017. All rights reserved.