|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.code.regexp.Pattern
public class Pattern
A compiled representation of a regular expression. This is a wrapper for the java.util.regex.Pattern with support for named capturing groups. The named groups are specified with "(?<name>exp)", which is identical to Java 7 named groups.
Constructor Summary | |
---|---|
protected |
Pattern(String regex,
int flags)
Constructs a named pattern with the given regular expression and flags |
Method Summary | |
---|---|
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 |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected Pattern(String regex, int flags)
regex
- the expression to be compiledflags
- Match flags, a bit mask that may include:
Method Detail |
---|
public static Pattern compile(String regex)
regex
- the expression to be compiled
public 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 group
public 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 instance
IndexOutOfBoundsException
- if instance index is out of boundspublic int flags()
public Matcher matcher(CharSequence input)
input
- The character sequence to be matched
public Pattern pattern()
Pattern
public 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:
Matcher.replaceAll(String)
Matcher.replaceFirst(String)
Matcher.appendReplacement(StringBuffer, String)
replacementPattern
- the input string to be evaluated
PatternSyntaxException
- 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 above
public String[] split(CharSequence input)
input
- The character sequence to be split
public String toString()
toString
in class Object
public static Map<String,List<GroupInfo>> extractGroupInfo(String namedPattern)
namedPattern
- regex the regular expression pattern to parse
public boolean equals(Object obj)
equals
in class Object
public int hashCode()
hashCode
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |