Class Patterns

java.lang.Object
io.sundr.utils.Patterns

public final class Patterns extends Object
  • Method Details

    • regex

      public static Patterns.PatternMatcher regex()
      Returns a PatternMatcher configured to use regex patterns explicitly.
      Returns:
      a regex pattern matcher
    • glob

      public static Patterns.PatternMatcher glob()
      Returns a PatternMatcher configured to use glob patterns explicitly.
      Returns:
      a glob pattern matcher
    • auto

      public static Patterns.PatternMatcher auto()
      Returns a PatternMatcher configured to auto-detect pattern type. This is the default behavior and equivalent to using the static methods directly.
      Returns:
      an auto-detecting pattern matcher
    • match

      public static Optional<String> match(String content, String pattern)
    • match

      public static Optional<String> match(String content, String pattern, int index)
    • isIncluded

      public static boolean isIncluded(String target, String... includes)
    • isExcluded

      public static boolean isExcluded(String target, String... excludes)
    • matchesPattern

      public static boolean matchesPattern(String target, String pattern)
      Checks if the target string matches the given pattern. Automatically detects whether the pattern is a glob or regex pattern.
      Parameters:
      target - the string to match against
      pattern - the pattern (glob or regex)
      Returns:
      true if the target matches the pattern
    • isGlobPattern

      public static boolean isGlobPattern(String pattern)
      Determines if a pattern is a glob pattern or a regex pattern. Uses heuristics to detect common glob patterns vs regex patterns.
      Parameters:
      pattern - the pattern to analyze
      Returns:
      true if the pattern appears to be a glob pattern, false for regex
    • matchesGlob

      public static boolean matchesGlob(String target, String glob)
      Matches a target string against a glob pattern. Supports wildcards: * (any characters), ? (single character), ** (directory traversal).
      Parameters:
      target - the string to match
      glob - the glob pattern
      Returns:
      true if the target matches the glob pattern
    • globToRegex

      public static String globToRegex(String glob)
      Converts a glob pattern to a regular expression. Handles directory traversal (**), wildcards (*), and single character matches (?).
      Parameters:
      glob - the glob pattern
      Returns:
      the equivalent regular expression