I need to make use of regex in javascript
The situation is this: I need to get the text that is with you inside the element with the text class.
After picking up this text, I have to look at it if it contains certain words or expressions. Here's a list of what I need to capture:
- Any word enclosed in double quotation marks
- Any word in single quotes
- Any word that is within the array defined in javascript
If any of these cases are found in the text, they should apply an html element only around those terms found . Here's the example:
"Esse texto está entre aspas". Esse aqui não está. Não esqueça de colocar cláusula WHERE no seu UPDATE
How to stay:
<span>"Esse texto está entre aspas"</span>. Esse aqui não está. Não esqueça de colocar cláusula WHERE no seu <span>UPDATE</span>
What I can not do is get these 3 items and apply them to a replace simultaneously in my text. I have identified in the code below the regular expressions and the array of words that I need to deal with. But I can not give replace taking the value found.
$(".texto").each(function(){
var termos = ["insert", "update", "delete"];
var texto = $(this).text();
var aspasDuplas = "(\"(.*?)\"){1,}";
var aspasSimples = "(\'(.*?)\'){1,}";
// Fazer o replace
})
How can I resolve this?