This is also usable, although it requires the variables to receive the captures
to be declared ahead of time:
proc match(src: string, pat: string, c0: var string): bool =
let caps = src.match(pat)
if caps.len == 1:
c0 = caps[0]
return true
proc match(src: string, pat: string, c0, c1: var string): bool =
let caps = src.match(pat)
if caps.len == 2:
c0 = caps[0]
c1 = caps[1]
return true
proc match(src: string, pat: string, c0, c1, c2: var string): bool =
let caps = src.match(pat)
if caps.len == 3:
c0 = caps[0]
c1 = caps[1]
c2 = caps[1]
return true
let src = "3 foxes: 0x1234"
var a, b: string
if src.match("(%a+).*0x(%x+)", a, b):
echo "a = " & a
echo "b = " & b