I have this code here:
<!DOCTYPE html>
<html>
<body>
<p id="demo">Display the result here.</p>
<input type = "text" value = "ood" id = "txt1"/>
<script>
var myString = "How much wood could a wood chuck chuck";
var myWord = document.getElementById("txt1").value; // ood
var myPattern = /.myWord/; // I want this to be /.ood/
var myResult = myString.match(myPattern);
document.getElementById("demo").innerHTML = myResult;
</script>
</body>
</html>
Now what I want to do here is that I want the value of the txt1 which is ood to be matched in myString.
But putting the variable myWord into the myPattern like this: /.myWord/ won't work. Need help please. Many thanks
UPDATE:
I did everything as what it is in the answers but it returns wood,wood instead of wood only, I just wanted to get only 1 match. Just like using for example /.ood/ - this only returns 1 match. Please help
And also, how can I get the word wood by having only od in my input text. I just wanted this for searching..
RegExpconstructor syntax asvar myPattern = new RegExp('\.' + myWord, 'gi');