Class Pattern
- All Implemented Interfaces:
Serializable
- Since:
- 0.1.9
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Pattern
Compiles the given regular expression into a patternstatic Pattern
Compiles the given regular expression into a pattern with the given flagsboolean
extractGroupInfo
(String namedPattern) Parses info on named capture groups from a patternint
flags()
Returns this pattern's match flagsGets the names and group info (group index and string position within the named pattern) of all named capture groupsGets the names of all capture groupsint
hashCode()
int
Gets the group index of a named capture groupint
Gets the group index of a named capture group at the specified index.matcher
(CharSequence input) Creates a matcher that will match the given input against this pattern.Returns the original regular expression (including named groups)pattern()
Returns the wrappedPattern
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.Returns the regular expression from which this pattern was compiled.toString()
Returns a string representation of this pattern
-
Field Details
-
UNIX_LINES
public static final int UNIX_LINES- See Also:
-
CASE_INSENSITIVE
public static final int CASE_INSENSITIVE- See Also:
-
COMMENTS
public static final int COMMENTS- See Also:
-
MULTILINE
public static final int MULTILINE- See Also:
-
LITERAL
public static final int LITERAL- See Also:
-
DOTALL
public static final int DOTALL- See Also:
-
UNICODE_CASE
public static final int UNICODE_CASE- See Also:
-
CANON_EQ
public static final int CANON_EQ- See Also:
-
-
Constructor Details
-
Pattern
Constructs a named pattern with the given regular expression and flags- Parameters:
regex
- the expression to be compiledflags
- Match flags, a bit mask that may include:
-
-
Method Details
-
compile
Compiles the given regular expression into a pattern- Parameters:
regex
- the expression to be compiled- Returns:
- the pattern
-
compile
Compiles the given regular expression into a pattern with the given flags- Parameters:
regex
- the expression to be compiledflags
- Match flags, a bit mask that may include:- Returns:
- the pattern
-
indexOf
Gets the group index of a named capture group- Parameters:
groupName
- name of capture group- Returns:
- group index or -1 if not found
-
indexOf
Gets the group index of a named capture group at the specified index. If only one instance of the named group exists, use index 0.- Parameters:
groupName
- name of capture groupindex
- the instance index of the named capture group within the pattern; e.g., index is 2 for the third instance- Returns:
- group index or -1 if not found
- Throws:
IndexOutOfBoundsException
- if instance index is out of bounds
-
flags
public int flags()Returns this pattern's match flags- Returns:
- The match flags specified when this pattern was compiled
-
matcher
Creates a matcher that will match the given input against this pattern.- Parameters:
input
- The character sequence to be matched- Returns:
- A new matcher for this pattern
-
pattern
Returns the wrappedPattern
- Returns:
- the pattern
-
standardPattern
Returns the regular expression from which this pattern was compiled.- Returns:
- The source of this pattern
-
namedPattern
Returns the original regular expression (including named groups)- Returns:
- The regular expression
-
groupNames
Gets the names of all capture groups- Returns:
- the list of names
-
groupInfo
Gets the names and group info (group index and string position within the named pattern) of all named capture groups- Returns:
- a map of group names and their info
-
replaceProperties
Replaces group-name properties (e.g.,${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:- Parameters:
replacementPattern
- the input string to be evaluated- Returns:
- the modified string
- Throws:
PatternSyntaxException
- group name was not found
-
split
Splits the given input sequence around matches of this pattern.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.
- Parameters:
input
- The character sequence to be splitlimit
- The result threshold, as described above- Returns:
- The array of strings computed by splitting the input around matches of this pattern
-
split
Splits the given input sequence around matches of this pattern.- Parameters:
input
- The character sequence to be split- Returns:
- The array of strings computed by splitting the input around matches of this pattern
-
toString
Returns a string representation of this pattern -
extractGroupInfo
Parses info on named capture groups from a pattern- Parameters:
namedPattern
- regex the regular expression pattern to parse- Returns:
- list of group info for all named groups
-
equals
-
hashCode
public int hashCode()
-