leafiy
5/18/2018 - 6:53 PM

escapeRegExp #js #regex

转意字符串

const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
// escapeRegExp('(test)') -> \\(test\\)