From 863e86273142e7d768138519ebf7176324404fdb Mon Sep 17 00:00:00 2001 From: Sam Nicholls Date: Sat, 29 Dec 2012 18:42:32 +0000 Subject: [PATCH] Escape snippet --- snippets.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/snippets.js b/snippets.js index 55c7fec..808ca4c 100644 --- a/snippets.js +++ b/snippets.js @@ -263,3 +263,8 @@ Number.prototype.numberFormat = function(dec_places){ parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, sep); return parts.join(dec_point); } + +// http://simonwillison.net/2006/Jan/20/escape/#p-6 +String.prototype.escape = function() { + return this.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); +}