Simon Willison’s Weblog

Entries tagged javascript in Jan, 2006

Filters: Type: entry × Year: 2006 × Month: Jan × javascript ×

Escaping regular expression characters in JavaScript

JavaScript’s support for regular expressions is generally pretty good, but there is one notable omission: an escaping mechanism for literal strings. Say for example you need to create a regular expression that removes a specific string from the end of a string. If you know the string you want to remove when you write the script this is easy:

[... 362 words]