What I want is to include the variable within (/.../)
and not its value.
Code:
var str = 'Seu texto aqui!';
if (str.match(/texto/)) {
alert('Palavra encontrada.');
}
Instead of manually defining, I want something dynamic coming from a variable.
Example:
var res = document.getElementById('txt').value = 'texto';
var str = 'Seu texto aqui!';
if (str.match(/res/)) {
alert('Palavra encontrada.');
}
But it does not work (/res/)
, as I can not figure out how to play a variable assignment within the match (String)
method