2
What I want is to include the variable within the (/.../)
and not its value.
Code:
var str = 'Seu texto aqui!';
if (str.match(/texto/)) {
alert('Palavra encontrada.');
}
Instead of setting manually, I want something dynamic 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 doesn’t work (/res/)
, because I’m not able to figure out how to play an assignment of the variable within the method match (String)