> it requires the variables to receive the captures to be declared ahead of 
> time:

This might work (untested):
    
    
    template match(src: string, pat: string, c0, c1: untyped): bool =
      
      when compiles(c0):
        c0 = ""
      else:
        var c0 = ""
      
      when compiles(c1):
        c1 = ""
      else:
        var c1 = ""
      
      let caps = src.match(src, pat)
      if caps.len == 2:
        c0 = caps[0]
        c1 = caps[1]
        return true
    
    let src = "3 foxes: 0x1234"
    
    if test.match(src, "(%a+).*0x(%x+)", a, b):
      echo "a = " & a
      echo "b = " & b
    

Reply via email to