Class RegExpGenerator


  • public class RegExpGenerator
    extends java.lang.Object
    Analyze a set of strings and return a suitable Regular Expression. Unlikely to be an optimal Regular Expression!!

    Typical usage is:

     
     		RegExpGenerator generator = new RegExpGenerator();
    
     		generator.train("janv.");
     		generator.train("oct");
     		generator.train("dec.");
     		...
    
     		String result = generator.getResult();
     
     
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getResult()
      Given the set of Strings trained (See @link #train(String)) return a Regular Expression which will accept any of the training set.
      java.util.Set<java.lang.String> getValues()
      Get the set of Strings (in upper case) used to train the Generator.
      boolean isDigit()  
      boolean isOther()  
      static boolean isSpecial​(char ch)
      Is the supplied character reserved a special meaning in Regular Expressions? Note: We do not declare '-' as a special character, so should not be used in a Character Class
      static java.lang.String merge​(java.lang.String firstRE, java.lang.String secondRE)  
      static java.lang.String slosh​(char ch)  
      static java.lang.String slosh​(java.lang.String input)
      Return an escaped String (similar to Pattern.quote but not unconditional).
      void train​(java.lang.String input)
      This method should be called for each string in the set.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RegExpGenerator

        public RegExpGenerator()
      • RegExpGenerator

        public RegExpGenerator​(int maxSetSize,
                               java.util.Locale locale)
    • Method Detail

      • isSpecial

        public static boolean isSpecial​(char ch)
        Is the supplied character reserved a special meaning in Regular Expressions? Note: We do not declare '-' as a special character, so should not be used in a Character Class
        Parameters:
        ch - The character to test.
        Returns:
        True if the character is reserved.
      • slosh

        public static java.lang.String slosh​(char ch)
      • merge

        public static java.lang.String merge​(java.lang.String firstRE,
                                             java.lang.String secondRE)
      • slosh

        public static java.lang.String slosh​(java.lang.String input)
        Return an escaped String (similar to Pattern.quote but not unconditional).
        Parameters:
        input - The String to be protected.
        Returns:
        An escaped String.
      • isOther

        public boolean isOther()
      • isDigit

        public boolean isDigit()
      • train

        public void train​(java.lang.String input)
        This method should be called for each string in the set.
        Parameters:
        input - The String to be used as part of the set.
      • getResult

        public java.lang.String getResult()
        Given the set of Strings trained (See @link #train(String)) return a Regular Expression which will accept any of the training set.
        Returns:
        A regular expression matching the training set.
      • getValues

        public java.util.Set<java.lang.String> getValues()
        Get the set of Strings (in upper case) used to train the Generator.
        Returns:
        The set of Strings (in upper case).