Skip to content

Commit

Permalink
document escapeRegExp
Browse files Browse the repository at this point in the history
  • Loading branch information
arve0 committed May 20, 2018
1 parent 119b34e commit 3b650c2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ exports.hasDelimiter = function (where, options) {
};
};

function escapeRegExp(s) {
return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
}

/**
* Removes last curly from string.
*/
Expand All @@ -193,13 +189,24 @@ exports.removeDelimiter = function (str, options) {
const end = escapeRegExp(options.rightDelimiter);

let curly = new RegExp(
'[ \\n]?' + start + '[^' + start + end + end + ']+' + end + '$'
'[ \\n]?' + start + '[^' + start + end + ']+' + end + '$'
);
let pos = str.search(curly);

return pos !== -1 ? str.slice(0, pos) : str;
};

/**
* Escapes special characters in string s such that the string
* can be used in `new RegExp`. For example "[" becomes "\\[".
*
* @param {string} s Regex string.
* @return {string} Escaped string.
*/
function escapeRegExp (s) {
return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
}

/**
* find corresponding opening block
*/
Expand Down

0 comments on commit 3b650c2

Please sign in to comment.