;An inbuilt command to do more or less this:

; This command works the same as $wildtok although uses a regular expression instead of a wildcard match.

; $regtok(tokens,re,N,C)
; Returns the Nth token that matches the regular expression string.
;
; $regtok(hello how are you, /o/, 0, 32) = 3
; $regtok(hello how are you, /o.$/, 1, 32) = how
;
; If you specify zero for N, it returns the total number of matching tokens.

regtok {
If ($isid) {
var %a = 1,%b = $3,%d = 0,%z = $!gettok($1, $chr(37) $+ a,$4)
If (%b <= 0) || (%b !isnum) { var %b = -1 }
while ($eval(%z,2)) {
If ($regex($ifmatch,$2)) { If (%b == -1) { inc %d } | Else { dec %b } }
If (%b == 0) { return $eval(%z,2) }
inc %a
}
If (%b == -1) { return %d }
return
}
}