Class Regex


  • public final class Regex
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.regex.Pattern getPattern​(java.lang.String regex)
      Compiles the supplied regex into a Pattern and then caches it util it's needed next (compiling regex is slow).
      static java.util.regex.Pattern getPatternContainingOneOf​(java.lang.String... strings)
      Gets a regex pattern object that will match strings that contain any of the given strings
      static java.util.regex.Pattern getPatternForContainsString​(java.lang.String string)
      Gets a regex pattern object that will match strings that contains the given string
      static java.util.regex.Pattern getPatternForEndsWith​(java.lang.String string)
      Gets a regex pattern object that will match strings that end with the given string
      static java.util.regex.Pattern getPatternForExactString​(java.lang.String string)
      Gets a regex pattern object that will match strings that are exactly the given string
      static java.util.regex.Pattern getPatternForExactString​(java.lang.String string, boolean optionalQuantifier)
      Gets a regex pattern object that will match strings that are exactly the given string
      static java.util.regex.Pattern getPatternForExactStrings​(java.lang.String... strings)
      Gets a regex pattern object that will match strings that equal any of the given strings
      static java.util.regex.Pattern getPatternForStartsWith​(java.lang.String string)
      Gets a regex pattern object that will match strings that start with the given string
      static java.util.List<java.util.regex.Pattern> getPatternsForContainsStrings​(java.lang.String... strings)  
      static java.util.List<java.util.regex.Pattern> getPatternsForExactStrings​(java.lang.String... strings)  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getPatternForExactString

        public static java.util.regex.Pattern getPatternForExactString​(java.lang.String string)
        Gets a regex pattern object that will match strings that are exactly the given string
        Parameters:
        string - a regular string of text
        Returns:
        a Pattern object
      • getPatternForExactString

        public static java.util.regex.Pattern getPatternForExactString​(java.lang.String string,
                                                                       boolean optionalQuantifier)
        Gets a regex pattern object that will match strings that are exactly the given string
        Parameters:
        string - a regular string of text
        optionalQuantifier - whether this string should also match quantified strings e.g. Jug of water (14)
        Returns:
        a Pattern object
      • getPatternForStartsWith

        public static java.util.regex.Pattern getPatternForStartsWith​(java.lang.String string)
        Gets a regex pattern object that will match strings that start with the given string
        Parameters:
        string - a regular string of text
        Returns:
        a Pattern object
      • getPatternForEndsWith

        public static java.util.regex.Pattern getPatternForEndsWith​(java.lang.String string)
        Gets a regex pattern object that will match strings that end with the given string
        Parameters:
        string - a regular string of text
        Returns:
        a Pattern object
      • getPatternForContainsString

        public static java.util.regex.Pattern getPatternForContainsString​(java.lang.String string)
        Gets a regex pattern object that will match strings that contains the given string
        Parameters:
        string - a regular string of text
        Returns:
        a Pattern object
      • getPatternForExactStrings

        public static java.util.regex.Pattern getPatternForExactStrings​(java.lang.String... strings)
        Gets a regex pattern object that will match strings that equal any of the given strings
        Parameters:
        strings - one or more regular strings of text
        Returns:
        a Pattern object
      • getPatternContainingOneOf

        public static java.util.regex.Pattern getPatternContainingOneOf​(java.lang.String... strings)
        Gets a regex pattern object that will match strings that contain any of the given strings
        Parameters:
        strings - one or more regular strings of text
        Returns:
        a Pattern object
      • getPatternsForExactStrings

        public static java.util.List<java.util.regex.Pattern> getPatternsForExactStrings​(java.lang.String... strings)
      • getPatternsForContainsStrings

        public static java.util.List<java.util.regex.Pattern> getPatternsForContainsStrings​(java.lang.String... strings)
      • getPattern

        public static java.util.regex.Pattern getPattern​(java.lang.String regex)
        Compiles the supplied regex into a Pattern and then caches it util it's needed next (compiling regex is slow).
        Parameters:
        regex - a valid regex pattern
        Returns:
        a Pattern compiled from the regex or retrieved from the cache of previously requested Patterns.