3
I need to use 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 should analyze whether it contains any words or expressions. Here is a list of what I need to capture:
- Any word between double quotes
- Any word between single quotes
- Any word that is inside the array defined in javascript
If any of these cases are found in the text, it should apply an html element only around these terms have you found. Follow the example:
"Esse texto está entre aspas". Esse aqui não está. Não esqueça de colocar cláusula WHERE no seu UPDATE
As it should be:
<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’t do is take these three items and apply them to a replace simultaneously in my text. I identified in the code below, the regular expressions and the array of words I need to treat. However I cannot 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 fix this?
Very good guy. Simple and easy to understand! :)
– alan
Excellent Juniornunes! Very good indeed! The explanation is great too!
– DiChrist