Avoid repeated creation of a simple RegExp object.

This helps avoid creation of tens or hundreds of thousands of objects for the doc in #4487, which reduces cumulative memory allocations by about 2%. Not a huge improvement, but not bad for something so simple.