Class PathGroupExtractor

java.lang.Object
org.mockserver.matchers.PathGroupExtractor

public class PathGroupExtractor extends Object
Extracts the regex capture groups from a matched expectation's path pattern against the actual request path, so they can be exposed to response/forward templates.

The pattern is compiled with the same flags NottableString.matches(String, boolean) uses for path matching — case-insensitive matching uses DOTALL | CASE_INSENSITIVE | UNICODE_CASE and the opt-in matchExactCase mode uses DOTALL only — and is run as an anchored full match, so a request that matched the path also extracts its groups (no case/DOTALL divergence). Both numbered groups and Java named groups (?<name>...) are captured. The returned list is 1-based aligned with Matcher group numbering: index 0 is the whole match and index 1 the first capturing group, so a template author can use the indices they would naturally expect from the pattern. A group that did not participate in the match yields null in the list (and is omitted from the named map).

This is best-effort: a literal path with no capturing groups, a path that is not a regex, or a pattern that fails to compile all yield no groups (an empty result), and never throw, so the match decision — made elsewhere — is never affected by group extraction.

Author:
jamesdbloom
  • Method Details

    • extract

      public static PathGroupExtractor.PathGroups extract(String patternValue, String actualPath, boolean caseSensitive)
      Runs patternValue as an anchored full-match regex against actualPath and returns its capture groups. caseSensitive selects the same Pattern flags the path matcher used (false — the default — uses DOTALL | CASE_INSENSITIVE | UNICODE_CASE; true — the opt-in matchExactCase mode — uses DOTALL only), so extraction succeeds for exactly the requests that matched. Returns a PathGroupExtractor.PathGroups with no groups when the pattern is null/blank, has no capturing groups, does not match, or fails to compile.