Adds test for #524.
Generates a unique match array for regex fns. Closes #524.
Allocates only enough memory to generate regex results.
Merge #533 r=@jiahuang: Generate unique match array for regex functions.

Reusing this state broke nested replacer functions in regexes.