firefox-simple-blocker icon indicating copy to clipboard operation
firefox-simple-blocker copied to clipboard

Add simple wildcard mode

Open caugner opened this issue 5 years ago • 0 comments

A simple wildcard mode would allow to define items like https://*facebook.com/* by escaping all special characters except *.

Here's animplementation that you could use:

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

function escapeRegExpWithWildcard(regexp) {
  const escapedRegExp = escapeRegExp(regexp);

  const escapedWildcard = escapeRegExp("*");
  const escapedWildcardRegexp = new RegExp(escapeRegExp(escapedWildcard), "g");

  return escapedRegExp.replace(escapedWildcardRegexp, ".*?");
}

caugner avatar Apr 15 '20 10:04 caugner