Package snap.parse

Class Regex

java.lang.Object
snap.parse.Regex

public class Regex extends Object
A class for building regular expressions like a string buffer.
  • Field Details

  • Constructor Details

    • Regex

      public Regex(String aName, String aPattern)
      Constructor with given pattern and name.
  • Method Details

    • getName

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

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

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

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

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

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

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

      public Matcher getMatcher()
      Returns the shared matcher.
    • 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, String... theParts)
      Adds a group.
    • addChars

      public void addChars(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 String toString()
      Returns a string representation of regex.
      Overrides:
      toString in class 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(String aPattern)
      Returns the literal length of pattern.
    • getLiteralChar

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