Package snap.parse

Class RegexBuilder

java.lang.Object
snap.parse.RegexBuilder

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

  • Constructor Details

    • RegexBuilder

      public RegexBuilder(String aName)
      Constructor with given pattern and name.
  • Method Details

    • build

      public Regex build()
      Builds and returns a regex.
    • getPattern

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

      public void addGroup(RegexBuilder.Op anOp, String... theParts)
      Adds a group.
    • addChars

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

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

      public RegexBuilder addLetter()
      Adds any letter.
    • addLetterLower

      public RegexBuilder addLetterLower()
      Adds any letter.
    • addLetterUpper

      public RegexBuilder addLetterUpper()
      Adds any letter.
    • addAnyChar

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

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

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

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

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

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

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