Class RegexUtil

java.lang.Object
org.rapidcontext.util.RegexUtil

public final class RegexUtil extends Object
A set of utility methods for handling regular expressions.
Version:
1.0
  • Method Details

    • firstMatch

      public static String firstMatch(Pattern re, String str)
      Returns the first match for a regular expression.
      Parameters:
      re - the compiled regex pattern
      str - the string to match
      Returns:
      the matched substring, or null if no match was found
    • firstMatch

      public static String firstMatch(Pattern[] arr, String str)
      Returns the first match from an array of regular expressions.
      Parameters:
      arr - the array of compiled regex patterns
      str - the string to match
      Returns:
      the matched substring, or null if no match was found
    • fromGlob

      public static String fromGlob(String glob)
      Converts a glob expression to a regular expression. Handles the special characters '?', '*' and '**'.
      Parameters:
      glob - the glob to convert
      Returns:
      the corresponding regular expression