Hello expert,
I have a simple text line contains two words with a blank space. I am struggling to make regular expression for the same.
In past, when I have single word to match with a single line, i did the following and it was seamless..
var inparam = document.getElementById("inparam").value;
var inputuser = inparam;
var re = new RegExp(inputuser,"g");
var matchtext = re;
var result = matchtext.test(line);
alert(result);
As you can see, I am getting a dynamic string to match with the line. In my example, the variable "inparam" taking a value from the element named inparam. I have made an object to regular expression class with "re", and then I am matching it.
Let, line="Hello World"
inparam="Hello"
Now consider I am receiving two separate values from different elements with blank space, then what should be my object look like??
Let, line="Hello World"
firstin="Hello"
secondin="World"
I have tried this but didn't worked..
var firstin = document.getElementById("firstin").value;
var secondin = document.getElementById("secondin").value;
var inputfirst = firstin;
var inputsecond = secondin;
var re = new RegExp(inputfirst+"\s"+inputsecond,"g");
var matchtext = re;
var result = matchtext.test(line);
alert(result);
Any help or hint please???