I'm trying to use variables in matching in javascript, but for some reason it's not working. In console, when I tried to alert, it says "ERROR: Execution of script 'test matching' failed! Cannot read property 'length' of null". What am I doing wrong?
// ==UserScript==
// @name test matching
// @namespace John Galt
// @description Basic Google Hello
// @match *^https://www.google.com/$*
// @version 1
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant GM_xmlhttpRequest
// @run-at document-end
// ==/UserScript==
var temp = "findThis";
var string = "one two findThis three findThis four";
var tempArray = string.match("/"+temp+"/g");
var tempArrayCount = tempArray.length;
alert(tempArrayCount);
I need it for matching not replacing.