Friday, 11 August 2017

How to pass a variable into the regex expression in javascript?

I'm making a list search tool to check for a specific name in a long list. I have been successful at hard coding the name into the regex, but I need it to be dynamic.
Here is the code:



    function processString(){
document.getElementById('textArea').value = "";
var inputString = document.getElementById('textBox').value;
var userIn = document.getElementById('userInput').value;
var regex = //use variable 'userIn' for regex
$('#textArea').html(result);


if(result != null){
for(var i = 0; i < result.length; i++){
document.getElementById('textArea').value += result[i] + '\r\n';
}
}

}


codepen

No comments:

Post a Comment

casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...