Class RegexUtilities.SafeMatchResult

java.lang.Object
com.cedarsoftware.util.RegexUtilities.SafeMatchResult
Enclosing class:
RegexUtilities

public static class RegexUtilities.SafeMatchResult extends Object
Immutable container for regex match results. This class safely captures match data from a Matcher object, allowing the data to be used after the timeout-protected execution completes.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SafeMatchResult(Matcher matcher, String originalInput)
    Creates a SafeMatchResult from a Matcher.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    end()
    Returns the end index of the match.
    Returns the input string with the first match replaced with empty string.
    Returns the entire matched string (equivalent to group(0)).
    group(int index)
    Returns the captured group at the specified index.
    int
    Returns the number of capturing groups in the pattern.
    boolean
    Checks if a match was found.
    int
    Returns the start index of the match.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SafeMatchResult

      public SafeMatchResult(Matcher matcher, String originalInput)
      Creates a SafeMatchResult from a Matcher. If matcher is null or didn't match, creates an unmatched result.
      Parameters:
      matcher - The Matcher to capture data from (null if no match)
      originalInput - The original input string
  • Method Details

    • group

      public String group(int index)
      Returns the captured group at the specified index.
      Parameters:
      index - The group index (0 = entire match, 1+ = capturing groups)
      Returns:
      The captured string, or null if index is out of range or no match
    • group

      public String group()
      Returns the entire matched string (equivalent to group(0)).
      Returns:
      The matched string, or null if no match
    • groupCount

      public int groupCount()
      Returns the number of capturing groups in the pattern.
      Returns:
      Number of capturing groups (0 if no match)
    • matched

      public boolean matched()
      Checks if a match was found.
      Returns:
      true if the pattern matched, false otherwise
    • start

      public int start()
      Returns the start index of the match.
      Returns:
      Start index, or -1 if no match
    • end

      public int end()
      Returns the end index of the match.
      Returns:
      End index, or -1 if no match
    • getReplacement

      public String getReplacement()
      Returns the input string with the first match replaced with empty string. This is useful for iteratively processing a string by removing matched portions.
      Returns:
      The input string with the first match removed, or the original input if no match