Class RegexUtil

java.lang.Object
org.seppiko.commons.utils.RegexUtil

public class RegexUtil extends Object
Regular expression utility
Author:
Leonard Woo
See Also:
  • Method Details

    • matches

      public static boolean matches(String regex, CharSequence input)
      Compiles the given regular expression and attempts to match the given input against it.
      Parameters:
      regex - The expression to be compiled.
      input - The character sequence to be matched.
      Returns:
      Whether the regular expression matches on the input.
    • find

      public static String find(String regex, CharSequence input)
      Returns the input subsequence captured by the given index during match operation.
      Parameters:
      regex - The expression to be compiled.
      input - The character sequence to be matched.
      Returns:
      The (possibly empty) subsequence captured by the index during match, or empty if the group failed to match part of the input.
    • split

      public static String[] split(String regex, CharSequence input)
      Returns the input subsequence split by the given expression in a string array.
      Parameters:
      regex - The delimiting regular expression.
      input - The character sequence to be split.
      Returns:
      The array of strings computed by splitting the input around matches of this pattern. If the expression's syntax is invalid return an empty string array.
    • getMatcher

      public static Matcher getMatcher(String regex, CharSequence input) throws NullPointerException, IllegalArgumentException
      A matcher that will match the given input against this pattern.
      Parameters:
      regex - The expression to be compiled.
      input - The character sequence to be matched.
      Returns:
      Matcher instance.
      Throws:
      NullPointerException - If regex or input is null.
      IllegalArgumentException - if the expression's syntax is invalid.
    • getPattern

      public static Pattern getPattern(String regex) throws PatternSyntaxException, NullPointerException
      Compiles the given regular expression the given input against it.
      Parameters:
      regex - The expression to be compiled.
      Returns:
      Pattern The given regular expression compiled into a pattern.
      Throws:
      PatternSyntaxException - If the expression's syntax is invalid.
      NullPointerException - If regex is null.