Skip to content

Instantly share code, notes, and snippets.

@tbranyen
Created February 14, 2014 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbranyen/9008556 to your computer and use it in GitHub Desktop.
Save tbranyen/9008556 to your computer and use it in GitHub Desktop.
define(function(require, exports, module) {
"use strict";
var specialCharsExp = /[\^$\\\/.*+?()\[\]{}|]/g;
/**
* Escape special characters that may interfere with RegExp building.
*
* @param {String} value to escape.
* @return {String} safe value for RegExp building.
*/
function escapeDelimiter(delimiter) {
return delimiter.replace(specialCharsExp,"\\$&");
}
module.exports = escapeDelimiter;
});
@jdalton
Copy link

jdalton commented Feb 14, 2014

the regexp used in lodash is /[.*+?^${}()|[\]\\]/g let me compare a sec... yours escapes the / character and it doesn't need to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment