Class MetaPattern
- java.lang.Object
-
- org.apache.wicket.util.parse.metapattern.MetaPattern
-
- All Implemented Interfaces:
Serializable,IClusterable
- Direct Known Subclasses:
Group,OptionalMetaPattern
public class MetaPattern extends Object implements IClusterable
Useful class for constructing readable and reusable regular expressions.MetaPatterns can be constructed from a simple regular expression String, from other MetaPatterns (copy constructor), from a list of MetaPatterns or from an array of MetaPatterns. In this way, it is easy to build up larger patterns while transparently binding the capturing groups of each MetaPattern for easy object oriented access to capturing group matches.
A given MetaPattern can be converted to a Matcher or Pattern. Groups within the MetaPattern can be used to automatically reference capturing group values when a match is made with a Matcher object.
A variety of static constants are provided for use in constructing compound MetaPatterns. Also, a number of simple parsers have been constructed using MetaPatterns in the parsers subpackage.
- Author:
- Jonathan Locke
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static MetaPatternAMPERSANDConstant for ampersand.static MetaPatternANYTHINGConstant for anything (string).static MetaPatternANYTHING_NON_EMPTYConstant for anything non-empty (string).static MetaPatternAT_SIGNConstant for at.static MetaPatternBACKSLASHConstant for backslash.static MetaPatternCOLONConstant for colon.static MetaPatternCOMMAConstant for comma.static MetaPatternDASHConstant for dash.static MetaPatternDIGITConstant for digit.static MetaPatternDIGITSConstant for digits.static MetaPatternDOLLAR_SIGNConstant for dollar.static MetaPatternDOTConstant for dot.static MetaPatternDOUBLE_QUOTED_STRINGConstant for a double quoted string.static MetaPatternEQUALSConstant for equals.static MetaPatternEXCLAMATION_POINTConstant for excl.static MetaPatternFLOATING_POINT_NUMBERConstant for a floating point number.static MetaPatternHEXADECIMAL_DIGITConstant for hex digit.static MetaPatternHEXADECIMAL_DIGITSConstant for hex digits.static MetaPatternINTEGERConstant for an integer (of any size).static MetaPatternLEFT_CURLYConstant for left curly braces.static MetaPatternLEFT_PARENConstant for left paren.static MetaPatternLEFT_SQUAREConstant for left square bracket.static MetaPatternMINUSConstant for minus.static MetaPatternNON_WORDConstant for non-word.static MetaPatternOPTIONAL_STRINGConstant for an optional string.static MetaPatternOPTIONAL_WHITESPACEConstant for optional whitespace.static MetaPatternOPTIONAL_WORDConstant for an optional word.static MetaPatternPERCENTConstant for percent.static MetaPatternPERL_INTERPOLATIONConstant for perl interpolation.static MetaPatternPIPEConstant for pipe.static MetaPatternPLUSConstant for plus.static MetaPatternPOSITIVE_INTEGERConstant for a positive integer.static MetaPatternPOUND_SIGNConstant for pound.static MetaPatternRIGHT_CURLYConstant for right curly braces.static MetaPatternRIGHT_PARENConstant for right paren.static MetaPatternRIGHT_SQUAREConstant for right square bracket.static MetaPatternSEMICOLONConstant for semicolon.static MetaPatternSLASHConstant for slash.static MetaPatternSTARConstant for star.static MetaPatternSTRINGConstant for a string.static MetaPatternTILDEConstant for tilde.static MetaPatternUNDERSCOREConstant for underscore.static MetaPatternVARIABLE_NAMEConstant for a variable name.static MetaPatternWHITESPACEConstant for whitespace.static MetaPatternWORDConstant for a word.static MetaPatternXML_ATTRIBUTE_NAMEConstant for an XML attribute name.static MetaPatternXML_ELEMENT_NAMEConstant for an XML element name.
-
Constructor Summary
Constructors Constructor Description MetaPattern(String pattern)Constructor for a simple pattern.MetaPattern(List<MetaPattern> patterns)Constructs from a list of MetaPatternsMetaPattern(MetaPattern pattern)Copy constructor.MetaPattern(MetaPattern... patterns)Constructs from an array of MetaPatterns.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Matchermatcher(CharSequence input)Creates a matcher against a given input character sequence.Matchermatcher(CharSequence input, int flags)Creates a matcher with the given regexp compile flags.Patternpattern()Gets the regular expression Pattern for this MetaPattern by compiling it.Patternpattern(int flags)Gets the regular expression Pattern for this MetaPattern by compiling it using the given flags.StringtoString()Converts this MetaPattern to a String.
-
-
-
Field Detail
-
WHITESPACE
public static final MetaPattern WHITESPACE
Constant for whitespace.
-
OPTIONAL_WHITESPACE
public static final MetaPattern OPTIONAL_WHITESPACE
Constant for optional whitespace.
-
NON_WORD
public static final MetaPattern NON_WORD
Constant for non-word.
-
COMMA
public static final MetaPattern COMMA
Constant for comma.
-
COLON
public static final MetaPattern COLON
Constant for colon.
-
SEMICOLON
public static final MetaPattern SEMICOLON
Constant for semicolon.
-
SLASH
public static final MetaPattern SLASH
Constant for slash.
-
BACKSLASH
public static final MetaPattern BACKSLASH
Constant for backslash.
-
DOT
public static final MetaPattern DOT
Constant for dot.
-
PLUS
public static final MetaPattern PLUS
Constant for plus.
-
MINUS
public static final MetaPattern MINUS
Constant for minus.
-
DASH
public static final MetaPattern DASH
Constant for dash.
-
UNDERSCORE
public static final MetaPattern UNDERSCORE
Constant for underscore.
-
AMPERSAND
public static final MetaPattern AMPERSAND
Constant for ampersand.
-
PERCENT
public static final MetaPattern PERCENT
Constant for percent.
-
DOLLAR_SIGN
public static final MetaPattern DOLLAR_SIGN
Constant for dollar.
-
POUND_SIGN
public static final MetaPattern POUND_SIGN
Constant for pound.
-
AT_SIGN
public static final MetaPattern AT_SIGN
Constant for at.
-
EXCLAMATION_POINT
public static final MetaPattern EXCLAMATION_POINT
Constant for excl.
-
TILDE
public static final MetaPattern TILDE
Constant for tilde.
-
EQUALS
public static final MetaPattern EQUALS
Constant for equals.
-
STAR
public static final MetaPattern STAR
Constant for star.
-
PIPE
public static final MetaPattern PIPE
Constant for pipe.
-
LEFT_PAREN
public static final MetaPattern LEFT_PAREN
Constant for left paren.
-
RIGHT_PAREN
public static final MetaPattern RIGHT_PAREN
Constant for right paren.
-
LEFT_CURLY
public static final MetaPattern LEFT_CURLY
Constant for left curly braces.
-
RIGHT_CURLY
public static final MetaPattern RIGHT_CURLY
Constant for right curly braces.
-
LEFT_SQUARE
public static final MetaPattern LEFT_SQUARE
Constant for left square bracket.
-
RIGHT_SQUARE
public static final MetaPattern RIGHT_SQUARE
Constant for right square bracket.
-
DIGIT
public static final MetaPattern DIGIT
Constant for digit.
-
DIGITS
public static final MetaPattern DIGITS
Constant for digits.
-
INTEGER
public static final MetaPattern INTEGER
Constant for an integer (of any size).
-
FLOATING_POINT_NUMBER
public static final MetaPattern FLOATING_POINT_NUMBER
Constant for a floating point number.
-
POSITIVE_INTEGER
public static final MetaPattern POSITIVE_INTEGER
Constant for a positive integer.
-
HEXADECIMAL_DIGIT
public static final MetaPattern HEXADECIMAL_DIGIT
Constant for hex digit.
-
HEXADECIMAL_DIGITS
public static final MetaPattern HEXADECIMAL_DIGITS
Constant for hex digits.
-
ANYTHING
public static final MetaPattern ANYTHING
Constant for anything (string).
-
ANYTHING_NON_EMPTY
public static final MetaPattern ANYTHING_NON_EMPTY
Constant for anything non-empty (string).
-
WORD
public static final MetaPattern WORD
Constant for a word.
-
OPTIONAL_WORD
public static final MetaPattern OPTIONAL_WORD
Constant for an optional word.
-
VARIABLE_NAME
public static final MetaPattern VARIABLE_NAME
Constant for a variable name.
-
XML_ELEMENT_NAME
public static final MetaPattern XML_ELEMENT_NAME
Constant for an XML element name.
-
XML_ATTRIBUTE_NAME
public static final MetaPattern XML_ATTRIBUTE_NAME
Constant for an XML attribute name.
-
PERL_INTERPOLATION
public static final MetaPattern PERL_INTERPOLATION
Constant for perl interpolation.
-
DOUBLE_QUOTED_STRING
public static final MetaPattern DOUBLE_QUOTED_STRING
Constant for a double quoted string.
-
STRING
public static final MetaPattern STRING
Constant for a string.
-
OPTIONAL_STRING
public static final MetaPattern OPTIONAL_STRING
Constant for an optional string.
-
-
Constructor Detail
-
MetaPattern
public MetaPattern(String pattern)
Constructor for a simple pattern.- Parameters:
pattern- The regular expression pattern to compile
-
MetaPattern
public MetaPattern(MetaPattern pattern)
Copy constructor.- Parameters:
pattern- The meta pattern to copy
-
MetaPattern
public MetaPattern(MetaPattern... patterns)
Constructs from an array of MetaPatterns.- Parameters:
patterns- Array of MetaPatterns
-
MetaPattern
public MetaPattern(List<MetaPattern> patterns)
Constructs from a list of MetaPatterns- Parameters:
patterns- List of MetaPatterns
-
-
Method Detail
-
matcher
public final Matcher matcher(CharSequence input)
Creates a matcher against a given input character sequence.- Parameters:
input- The input to match against- Returns:
- The matcher
-
matcher
public final Matcher matcher(CharSequence input, int flags)
Creates a matcher with the given regexp compile flags. Once you call this method with a given regexp compile flag value, the pattern will be compiled. Calling it again with a different value for flags will not recompile the pattern.- Parameters:
input- The input to matchflags- One or more of the standard Java regular expression compile flags (seePattern.compile(String, int))- Returns:
- The matcher
-
pattern
public final Pattern pattern()
Gets the regular expression Pattern for this MetaPattern by compiling it.- Returns:
- Pattern compiled with default Java regular expression compile flags
-
pattern
public final Pattern pattern(int flags)
Gets the regular expression Pattern for this MetaPattern by compiling it using the given flags.- Parameters:
flags- One or more of the standard Java regular expression compile flags (seePattern.compile(String, int))- Returns:
- Equivalent Java regular expression Pattern compiled with the given flags
-
toString
public String toString()
Converts this MetaPattern to a String.- Overrides:
toStringin classObject- Returns:
- A String representing this MetaPattern
- See Also:
Object.toString()
-
-