Class Regex

  • public class Regex
    extends java.lang.Object
    A class for building regular expressions like a string buffer.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Regex.Op  
    • Field Summary

      Modifier and Type Field Description
      static java.lang.String Digit  
      static java.lang.String LetterLower  
      static java.lang.String LetterUpper  
      static java.lang.String WhiteSpace  
    • Constructor Summary

      Constructor Description
      Creates a new regex.
      Regex​(java.lang.String aName, java.lang.String aPattern)
      Creates a new regex with given pattern and name.
      Regex​(java.lang.String aName, java.lang.String aPattern, boolean isLiteral)
      Creates a new regex with given pattern and name.
    • Constructor Detail

      • Regex

        public Regex()
        Creates a new regex.
      • Regex

        public Regex​(java.lang.String aName,
                     java.lang.String aPattern)
        Creates a new regex with given pattern and name.
      • Regex

        public Regex​(java.lang.String aName,
                     java.lang.String aPattern,
                     boolean isLiteral)
        Creates a new regex with given pattern and name.
    • Method Detail

      • getName

        public java.lang.String getName()
        Returns the regex name.
      • setName

        public void setName​(java.lang.String aName)
        Sets the regex name.
      • getPattern

        public java.lang.String getPattern()
        Returns the regex pattern.
      • setPattern

        public void setPattern​(java.lang.String aPattern)
        Sets the pattern.
      • isLiteral

        public boolean isLiteral()
        Returns whether pattern is literal.
      • setLiteral

        public void setLiteral​(boolean aFlag)
        Sets whether pattern is literal.
      • getPatternCompiled

        public java.util.regex.Pattern getPatternCompiled()
        Returns the compiled pattern.
      • getPatternCompileFlags

        public int getPatternCompileFlags()
        Returns pattern compile flags.
      • getMatcher

        public java.util.regex.Matcher getMatcher​(java.lang.CharSequence anInput)
        Returns the shared matcher (initialized to the given char sequence if not yet created).
      • getLiteralLength

        public int getLiteralLength()
        Returns the literal length of this regex (the number of literal chars in the prefix).
      • getLiteralChar

        public char getLiteralChar()
        Returns the first literal in regex pattern (or 0 if not literal).
      • addGroup

        public void addGroup​(Regex.Op anOp,
                             java.lang.String... theParts)
        Adds a group.
      • addChars

        public void addChars​(java.lang.String... theParts)
        Adds a letter.
      • addChar

        public Regex addChar​(char c)
        Adds a literal char.
      • addLetter

        public Regex addLetter()
        Adds any letter.
      • addLetterLower

        public Regex addLetterLower()
        Adds any letter.
      • addLetterUpper

        public Regex addLetterUpper()
        Adds any letter.
      • addAnyChar

        public Regex addAnyChar()
        Adds any char (doesn't include newlines).
      • addDigit

        public Regex addDigit()
        Adds a digit: [0-9].
      • addNonDigit

        public Regex addNonDigit()
        Adds a non-digit: [^0-9].
      • addWhitespace

        public Regex addWhitespace()
        Adds whitespace char [ \t\n\x0B\f\r].
      • addNonWhitespace

        public Regex addNonWhitespace()
        Adds non-whitespace char: [^\s].
      • addWordCharacter

        public Regex addWordCharacter()
        Adds a word character: [a-zA-Z_0-9].
      • addNonWordCharacter

        public Regex addNonWordCharacter()
        Adds a non-word character: [^\w].
      • toString

        public java.lang.String toString()
        Returns a string representation of regex.
        toString in class java.lang.Object
      • isSpecialChar

        public static boolean isSpecialChar​(char c)
        Utility method to return whether given character is a special char.
      • isAncharChar

        public static boolean isAncharChar​(char c)
        Utility method to return whether char is an anchor char.
      • getLiteralLength

        public static int getLiteralLength​(java.lang.String aPattern)
        Returns the literal length of pattern.
      • getLiteralChar

        public static char getLiteralChar​(java.lang.String aPattern)
        Returns the first char of a pattern, if it's a literal char.