Question: I have problem use array keyword and non-casesensitive search in innerHTML
I am trying write Greasemonkey JS which will remove tags which are containning keywords 

```
 function removebadcriptts() {

 var  scriptslinks = ['jumper.php','redirect.php'];
 var theLinks = document.getElementsByTagName("script");

 for (var i=0; i<scriptslinks.length; i++)
 {
   for (var j=0;j<theLinks.length;j++)
   {
     if (theLinks[i].innerHTML.search("/"+scriptslinks[i]+"/i/")  !== -1)
      /keyword/i = regular expression for non-case is not working
     {     
      console.error("InnerHTML Keyword found ");      
      theLinks[j].parentNode.removeChild(theLinks[j]);
     } 
     else
     {
       console.error("InnerHTML Keyword  not found ");   
     }
   }
 }
}

```

Can anybody help howto remove and match this kind of scripts and remove from WEBpage also howto catch scripts which are injecting scripts into loaded webpage

Answer: 
When the Greasemonkey script is running, the scripts that are already on the page has already run. Removing them won't undo what these scripts did to the page.

Also the script that is inserted after the Greasemonkey script will not be catched, so this Greasemonkey probably will not work.

An alternative would be using NoScript add-on, because it is already designed to prevent scripts from running.

---

**Edit:** As the OP said that the primary problem is to make the search work, instead of storing patterns in a string inside an array, you can store patterns directly.

```
 var scriptslinks = [/jumper\.php/i, /redirect\.php/i];

```

And when matching

```
     if (theLinks[j].innerHTML.search(scriptslinks[i])  !== -1)

```

Note that a regex is passed directly to the search function. Also `theLinks[i]` should be `theLinks[j]`.

**Another solution:** Use a single pattern.

```
     if (theLinks[j].innerHTML.search(/jumper\.php|redirect\.php/i)  !== -1)

```

That way you don't have to make 2 level for loops, and I think it will be faster, as the engine can search for 2 patterns at once.
[`search`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/search) expects a [*RegExp* object](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp). So try this:

```
theLinks[i].innerHTML.search(new RegExp(scriptslinks[i], "i"))

```

Although you can pass a string too, it would be used create an *RegExp* object like `new RegExp(string)` but you can’t set the *i* modifier with that.

Furthermore, you should escape the special character of a regular expression like the `.`. You can use this method to do so:

```
RegExp.quote = function(str) {
    return str.replace(/(?=[\\^$*+?.()|{}[\]])/g, "\\");
}

```