Created
February 14, 2014 20:25
-
-
Save tbranyen/9008556 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the regexp used in lodash is
/[.*+?^${}()|[\]\\]/g
let me compare a sec... yours escapes the/
character and it doesn't need to.