| Index: lib/common.js |
| =================================================================== |
| --- a/lib/common.js |
| +++ b/lib/common.js |
| @@ -13,16 +13,28 @@ |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| "use strict"; |
| /** |
|
Manish Jethani
2018/02/21 14:41:59
I would call this function "textToRegExp" to match
hub
2018/02/21 21:38:00
Done.
|
| + * Escape string to match to be a regular expression string |
| + * @param {string} s the string to search for. |
| + * @return {string} regular expression representation of string match. |
| + */ |
| +function escapeRegExp(s) |
| +{ |
| + return s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); |
| +} |
| + |
| +exports.escapeRegExp = escapeRegExp; |
| + |
| +/** |
| * Converts filter text into regular expression string |
| * @param {string} text as in Filter() |
| * @return {string} regular expression representation of filter text |
| */ |
| function filterToRegExp(text) |
| { |
| return text |
| // remove multiple wildcards |