Package com.google.re2j
Class Pattern
java.lang.Object
com.google.re2j.Pattern
- All Implemented Interfaces:
Serializable
A compiled representation of an RE2 regular expression, mimicking the
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.
- Author:
- rsc@google.com (Russ Cox)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intFlag: case insensitive matching.static final intFlag: Unicode groups (e.g.static final intFlag: dot (.) matches all characters, including newline.static final intFlag: multiline matching:^and$match at beginning and end of line, not just beginning and end of input. -
Method Summary
Modifier and TypeMethodDescriptionstatic PatternCreates and returns a newPatterncorresponding to compilingregexwith the default flags (0).static PatternCreates and returns a newPatterncorresponding to compilingregexwith the default flags (0).static Patternstatic Patternbooleanfind(io.airlift.slice.Slice input) static booleanMatches aSliceagainst a regular expression (unanchored).static booleanintflags()Returns the flags used in the constructor.intReturns the number of capturing groups in this matcher's pattern.matcher(io.airlift.slice.Slice input) Creates a newMatchermatching the pattern against the input.booleanmatches(io.airlift.slice.Slice input) static booleanMatches aSliceagainst a regular expression.static booleanoptions()Returns the options used in the constructor.pattern()Returns the pattern used in the constructor.static StringReturns a literal pattern string for the specified string.io.airlift.slice.Slice[]split(io.airlift.slice.Slice input) Splits input around instances of the regular expression.io.airlift.slice.Slice[]split(io.airlift.slice.Slice input, int limit) Splits input around instances of the regular expression.toString()
-
Field Details
-
CASE_INSENSITIVE
public static final int CASE_INSENSITIVEFlag: case insensitive matching.- See Also:
-
DOTALL
public static final int DOTALLFlag: dot (.) matches all characters, including newline.- See Also:
-
MULTILINE
public static final int MULTILINEFlag: multiline matching:^and$match at beginning and end of line, not just beginning and end of input.- See Also:
-
DISABLE_UNICODE_GROUPS
public static final int DISABLE_UNICODE_GROUPSFlag: Unicode groups (e.g.\p\{Greek\}) will be syntax errors.- See Also:
-
-
Method Details
-
flags
public int flags()Returns the flags used in the constructor. -
options
Returns the options used in the constructor. -
pattern
Returns the pattern used in the constructor. -
compile
Creates and returns a newPatterncorresponding to compilingregexwith the default flags (0).- Parameters:
regex- the regular expression- Throws:
PatternSyntaxException- if the pattern is malformed
-
compile
-
compile
Creates and returns a newPatterncorresponding to compilingregexwith the default flags (0).- Parameters:
regex- the regular expressionflags- bitwise OR of the flag constantsCASE_INSENSITIVE,DOTALL, andMULTILINE- Throws:
PatternSyntaxException- if the regular expression is malformedIllegalArgumentException- if an unknown flag is given
-
compile
-
matches
Matches aSliceagainst a regular expression.- Parameters:
regex- the regular expressioninput- the input- Returns:
- true if the regular expression matches the entire input
- Throws:
PatternSyntaxException- if the regular expression is malformed
-
matches
-
matches
public boolean matches(io.airlift.slice.Slice input) -
find
Matches aSliceagainst a regular expression (unanchored).- Parameters:
regex- the regular expressioninput- the input- Returns:
- true if the regular expression matches the entire input
- Throws:
PatternSyntaxException- if the regular expression is malformed
-
find
-
find
public boolean find(io.airlift.slice.Slice input) -
matcher
Creates a newMatchermatching the pattern against the input.- Parameters:
input- the inputSlice
-
split
public io.airlift.slice.Slice[] split(io.airlift.slice.Slice input) Splits input around instances of the regular expression. It returns an array giving theSlices that occur before, between, and after instances of the regular expression. EmptySlices that would occur at the end of the array are omitted.- Parameters:
input- the inputSliceto be split- Returns:
- the split
Slices
-
split
public io.airlift.slice.Slice[] split(io.airlift.slice.Slice input, int limit) Splits input around instances of the regular expression. It returns an array giving theSlices that occur before, between, and after instances of the regular expression.If
limit <= 0, there is no limit on the size of the returned array. Iflimit == 0, emptySlices that would occur at the end of the array are omitted. Iflimit > 0, at most limitSlices are returned. The finalSlicecontains the remainder of the input, possibly including additional matches of the pattern.- Parameters:
input- the inputSliceto be splitlimit- the limit- Returns:
- the split
Slices
-
quote
Returns a literal pattern string for the specified string.This method produces a string that can be used to create a
Metacharacters or escape sequences in the input sequence will be given no special meaning.Patternthat would match the stringsas if it were a literal pattern.- Parameters:
s- The string to be literalized- Returns:
- A literal string replacement
-
toString
-
groupCount
public int groupCount()Returns the number of capturing groups in this matcher's pattern. Group zero denotes the enture pattern and is excluded from this count.- Returns:
- the number of capturing groups in this pattern
-