5
Consider the following string:
var texto = 'Esse é um texto de <span class="red"> teste </span>';
I need to transform the string into an array separating by space, ie:
var palavras = texto.split(" ");
The problem is that the text contains HTML and in that case the resulting array will be:
palavras[0] = 'Esse';
palavras[1] = 'é';
palavras[2] = 'um';
palavras[3] = 'texto';
palavras[4] = 'de';
palavras[5] = '<span';
palavras[6] = 'class="red">';
palavras[7] = 'teste';
palavras[8] = '</span>';
However I need the resulting array to be the following:
palavras[0] = 'Esse';
palavras[1] = 'é';
palavras[2] = 'um';
palavras[3] = 'texto';
palavras[4] = 'de';
palavras[5] = '<span class="red"> teste </span>';
How to do this using javascript?
Using regular expression, you have to divide by spaces except within tags
– Costamilam
@Guilhermecostamilam the problem is creating this regular expression...
– Filipe Moraes