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"; |
/** |
+ * Convert raw text into a regular expression string |
Manish Jethani
2018/02/22 07:08:27
Sorry, for consistency, can we say "Converts" inst
hub
2018/02/22 14:07:49
Done.
|
+ * @param {string} text the string to convert. |
Manish Jethani
2018/02/22 07:08:27
Nit: seems like we generally don't add periods at
hub
2018/02/22 14:07:49
Done.
|
+ * @return {string} regular expression representation of string match. |
Manish Jethani
2018/02/22 07:08:28
"string match" seems to imply something, do you th
hub
2018/02/22 14:07:50
Done.
|
+ */ |
+function textToRegExp(text) |
+{ |
+ return text.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); |
+} |
+ |
+exports.textToRegExp = textToRegExp; |
+ |
+/** |
* 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 |