Step: Capturing groups

Capturing groups

Parentheses ( ... ) create a capturing group — a sub-match you can extract separately from the full match.

Why it matters: capturing is how you pull part of a match out — the value from key=value, the domain from an email, the id from a URL.

Example: in \w+=(\w+), the whole key=value matches, but the group captures just the value. This exercise shows the captured value for each pair.

Your turn: capture each value with \w+=(\w+).

Pitfall: need to group without capturing (e.g. just for alternation)? Use a non-capturing group (?: ... ) so it does not clutter your results.

Input:
key=value; host=local; port=8080
Expected:
[
  "value",
  "local",
  "8080"
]
Step 10 of 11