Add util.escape_regexp.

(imported from commit 3ba7caa0d444a64b228bcb5f5c658c8363ddfbf5)
This commit is contained in:
Tim Abbott 2013-07-01 17:51:03 -04:00
parent a4cf528fad
commit dc54a24766
1 changed files with 6 additions and 0 deletions

View File

@ -234,6 +234,12 @@ exports.strcmp = (function () {
};
}());
exports.escape_regexp = function(string) {
// code from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
// Modified to escape the ^ to appease jslint. :/
return string.replace(/([.*+?\^=!:${}()|\[\]\/\\])/g, "\\$1");
};
exports.array_compare = function util_array_compare(a, b) {
if (a.length !== b.length) {
return false;