Regex Grouping read this for more info.
As for your example you didn't group your pattern as below:
$regex(%var1,(\d\d\d\d))