Package com.cedarsoftware.util
Class RegexUtilities.SafeMatchResult
java.lang.Object
com.cedarsoftware.util.RegexUtilities.SafeMatchResult
- Enclosing class:
- RegexUtilities
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
ConstructorsConstructorDescriptionSafeMatchResult(Matcher matcher, String originalInput) Creates a SafeMatchResult from a Matcher. -
Method Summary
Modifier and TypeMethodDescriptionintend()Returns the end index of the match.Returns the input string with the first match replaced with empty string.group()Returns the entire matched string (equivalent to group(0)).group(int index) Returns the captured group at the specified index.intReturns the number of capturing groups in the pattern.booleanmatched()Checks if a match was found.intstart()Returns the start index of the match.
-
Constructor Details
-
SafeMatchResult
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
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
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
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
-