Friday, September 01, 2006

Escaping Strings for Dynamic REs

Here's a simple replace fragment to escape the special characters in a string for building patterns for a dynamic regular expression:

.replace(/([*^$?{}()[\]])/g, "\\$1")

No comments: