factored out regex generation