Capturing Groups
Extract substrings from matches.
Capturing Groups
Parentheses in a regex create capturing groups. Each group remembers the substring it matched, so you can extract structured pieces from a larger match.
A Single Capture
Wrapping part of a pattern in () captures it. The match output becomes a tuple: the whole match first, then each capture.
if let m = "v2".firstMatch(of: /v(\d+)/) {
print("Whole: \(m.0)")
print("Group: \(m.1)")
}