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 MetaPattern
AMPERSAND
Constant for ampersand.static MetaPattern
ANYTHING
Constant for anything (string).static MetaPattern
ANYTHING_NON_EMPTY
Constant for anything non-empty (string).static MetaPattern
AT_SIGN
Constant for at.static MetaPattern
BACKSLASH
Constant for backslash.static MetaPattern
COLON
Constant for colon.static MetaPattern
COMMA
Constant for comma.static MetaPattern
DASH
Constant for dash.static MetaPattern
DIGIT
Constant for digit.static MetaPattern
DIGITS
Constant for digits.static MetaPattern
DOLLAR_SIGN
Constant for dollar.static MetaPattern
DOT
Constant for dot.static MetaPattern
DOUBLE_QUOTED_STRING
Constant for a double quoted string.static MetaPattern
EQUALS
Constant for equals.static MetaPattern
EXCLAMATION_POINT
Constant for excl.static MetaPattern
FLOATING_POINT_NUMBER
Constant for a floating point number.static MetaPattern
HEXADECIMAL_DIGIT
Constant for hex digit.static MetaPattern
HEXADECIMAL_DIGITS
Constant for hex digits.static MetaPattern
INTEGER
Constant for an integer (of any size).static MetaPattern
LEFT_CURLY
Constant for left curly braces.static MetaPattern
LEFT_PAREN
Constant for left paren.static MetaPattern
LEFT_SQUARE
Constant for left square bracket.static MetaPattern
MINUS
Constant for minus.static MetaPattern
NON_WORD
Constant for non-word.static MetaPattern
OPTIONAL_STRING
Constant for an optional string.static MetaPattern
OPTIONAL_WHITESPACE
Constant for optional whitespace.static MetaPattern
OPTIONAL_WORD
Constant for an optional word.static MetaPattern
PERCENT
Constant for percent.static MetaPattern
PERL_INTERPOLATION
Constant for perl interpolation.static MetaPattern
PIPE
Constant for pipe.static MetaPattern
PLUS
Constant for plus.static MetaPattern
POSITIVE_INTEGER
Constant for a positive integer.static MetaPattern
POUND_SIGN
Constant for pound.static MetaPattern
RIGHT_CURLY
Constant for right curly braces.static MetaPattern
RIGHT_PAREN
Constant for right paren.static MetaPattern
RIGHT_SQUARE
Constant for right square bracket.static MetaPattern
SEMICOLON
Constant for semicolon.static MetaPattern
SLASH
Constant for slash.static MetaPattern
STAR
Constant for star.static MetaPattern
STRING
Constant for a string.static MetaPattern
TILDE
Constant for tilde.static MetaPattern
UNDERSCORE
Constant for underscore.static MetaPattern
VARIABLE_NAME
Constant for a variable name.static MetaPattern
WHITESPACE
Constant for whitespace.static MetaPattern
WORD
Constant for a word.static MetaPattern
XML_ATTRIBUTE_NAME
Constant for an XML attribute name.static MetaPattern
XML_ELEMENT_NAME
Constant 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 Matcher
matcher(CharSequence input)
Creates a matcher against a given input character sequence.Matcher
matcher(CharSequence input, int flags)
Creates a matcher with the given regexp compile flags.Pattern
pattern()
Gets the regular expression Pattern for this MetaPattern by compiling it.Pattern
pattern(int flags)
Gets the regular expression Pattern for this MetaPattern by compiling it using the given flags.String
toString()
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:
toString
in classObject
- Returns:
- A String representing this MetaPattern
- See Also:
Object.toString()
-
-