Class KiwiRegexes

java.lang.Object
org.kiwiproject.util.regex.KiwiRegexes

public final class KiwiRegexes extends Object
Static helper methods related to regular expression processing.
  • Method Details

    • extractMatchOrNull

      public static String extractMatchOrNull(Pattern pattern, String input)
      Extracts a regex match as a String, or return null if no match found.
      Parameters:
      pattern - the Pattern
      input - the input to match against
      Returns:
      a string containing the match, or null if no match found
    • extractMatchOrThrow

      public static String extractMatchOrThrow(Pattern pattern, String input)
      Extracts a regex match as a String, or throws an exception if no match found.
      Parameters:
      pattern - the Pattern
      input - the input to match against
      Returns:
      a string containing the match
      Throws:
      NoMatchesFoundException - if the input does not match the pattern
    • extractMatch

      public static Optional<String> extractMatch(Pattern pattern, String input)
      Extracts a regex match as a String.
      Parameters:
      pattern - the Pattern
      input - the input to match against
      Returns:
      an Optional containing the match, or empty Optional if no match
    • extractMatches

      public static Stream<MatchResult> extractMatches(Pattern pattern, String input)
      Match an input String against a Pattern and convert to a Stream of MatchResult.
      Parameters:
      pattern - the Pattern
      input - the input to match against
      Returns:
      a stream of MatchResult