Class RegexUtils


  • public class RegexUtils
    extends java.lang.Object
    Utility class to assist with regex operations.
    Since:
    5.0.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.regex.Pattern MATCH_NOTHING_PATTERN
      A pattern match that does not match anything.
    • Constructor Summary

      Constructors 
      Constructor Description
      RegexUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.regex.Pattern concatenate​(java.util.Collection<?> requiredValues, boolean caseInsensitive)
      Concatenate all elements in the given collection to form a regex pattern.
      static java.util.regex.Pattern createPattern​(java.lang.String pattern)
      Creates the pattern.
      static java.util.regex.Pattern createPattern​(java.lang.String pattern, int flags)
      Creates the pattern with the given flags.
      static boolean find​(java.lang.String pattern, java.lang.String string)
      Attempts to find the next sub-sequence of the input sequence that matches the pattern.
      static boolean find​(java.util.regex.Pattern pattern, java.lang.String string)
      Attempts to find the next sub-sequence of the input sequence that matches the pattern.
      static boolean isValidRegex​(java.lang.String pattern)
      Check to see if the specified pattern is a valid regular expression.
      static boolean matches​(java.util.regex.Pattern pattern, java.lang.String string)
      Matches the entire region for the string.
      static boolean matches​(java.util.regex.Pattern pattern, java.lang.String value, boolean completeMatch)
      Matches boolean.
      • Methods inherited from class java.lang.Object

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

      • MATCH_NOTHING_PATTERN

        public static final java.util.regex.Pattern MATCH_NOTHING_PATTERN
        A pattern match that does not match anything.
    • Constructor Detail

      • RegexUtils

        public RegexUtils()
    • Method Detail

      • isValidRegex

        public static boolean isValidRegex​(java.lang.String pattern)
        Check to see if the specified pattern is a valid regular expression.
        Parameters:
        pattern - the pattern
        Returns:
        whether this is a valid regex or not
      • concatenate

        public static java.util.regex.Pattern concatenate​(java.util.Collection<?> requiredValues,
                                                          boolean caseInsensitive)
        Concatenate all elements in the given collection to form a regex pattern.
        Parameters:
        requiredValues - the required values
        caseInsensitive - the case insensitive
        Returns:
        the pattern
      • createPattern

        public static java.util.regex.Pattern createPattern​(java.lang.String pattern)
        Creates the pattern. Matching is by default case insensitive.
        Parameters:
        pattern - the pattern, may not be null.
        Returns:
        the pattern or or MATCH_NOTHING_PATTERN if pattern is null or invalid.
      • createPattern

        public static java.util.regex.Pattern createPattern​(java.lang.String pattern,
                                                            int flags)
        Creates the pattern with the given flags.
        Parameters:
        pattern - the pattern, may be null.
        flags - the flags
        Returns:
        the compiled pattern or MATCH_NOTHING_PATTERN if pattern is null or invalid.
      • matches

        public static boolean matches​(java.util.regex.Pattern pattern,
                                      java.lang.String string)
        Matches the entire region for the string.
        Parameters:
        pattern - the pattern
        string - the string
        Returns:
        true/false
        See Also:
        Matcher.matches()
      • matches

        public static boolean matches​(java.util.regex.Pattern pattern,
                                      java.lang.String value,
                                      boolean completeMatch)
        Matches boolean.
        Parameters:
        pattern - the pattern
        value - the value
        completeMatch - the complete match
        Returns:
        true/false
      • find

        public static boolean find​(java.util.regex.Pattern pattern,
                                   java.lang.String string)
        Attempts to find the next sub-sequence of the input sequence that matches the pattern.
        Parameters:
        pattern - the pattern
        string - the string
        Returns:
        true/false
        See Also:
        Matcher.find()
      • find

        public static boolean find​(java.lang.String pattern,
                                   java.lang.String string)
        Attempts to find the next sub-sequence of the input sequence that matches the pattern.
        Parameters:
        pattern - the pattern
        string - the string
        Returns:
        true/false