Class MetaPattern

  • All Implemented Interfaces:
    java.io.Serializable, IClusterable
    Direct Known Subclasses:
    Group, OptionalMetaPattern

    public class MetaPattern
    extends java.lang.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 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​(java.lang.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​(java.util.List<MetaPattern> patterns)
        Constructs from a list of MetaPatterns
        Parameters:
        patterns - List of MetaPatterns
    • Method Detail

      • matcher

        public final java.util.regex.Matcher matcher​(java.lang.CharSequence input)
        Creates a matcher against a given input character sequence.
        Parameters:
        input - The input to match against
        Returns:
        The matcher
      • matcher

        public final java.util.regex.Matcher matcher​(java.lang.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 match
        flags - One or more of the standard Java regular expression compile flags (see Pattern.compile(String, int))
        Returns:
        The matcher
      • pattern

        public final java.util.regex.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 java.util.regex.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 (see Pattern.compile(String, int))
        Returns:
        Equivalent Java regular expression Pattern compiled with the given flags
      • toString

        public java.lang.String toString()
        Converts this MetaPattern to a String.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A String representing this MetaPattern
        See Also:
        Object.toString()