Improve regex generation