@LucianoZancan, based on your last example, I believe ResponseText is about an XML document serialized in an unconventional way.
In this case the interresante is to convert the ResponseText to an XML document and then work with the XML document:
Once we have the XML document, we can then search for all tags nomes
and retrieve propriedade name
from them.
var responseText = '\
array(9) {\n\
[0]=> string(10) "<document>"\n\
[1]=> string(24) "<nodo name="background">"\n\
[2]=> string(10) "<id>1</id>"\n\
[3]=> string(34) "<ocorrencia>0.3115942</ocorrencia>"\n\
[4]=> string(23) "<relacoes name="image">"\n\
[5]=> string(23) "<conexoes>48</conexoes>"\n\
[6]=> string(11) "</relacoes>"\n\
[7]=> string(11) "</nodo>"\n\
[8]=> string(11) "</document>"\n\
}\
';
var conteudoText = responseText.split("\n");
var conteudoXML = [];
for (var indice in conteudoText) {
var text = conteudoText[indice];
var indice = text.indexOf('"');
if (indice >= 0) {
var xml = text.substring(indice + 1, text.length - 1);
conteudoXML.push(xml);
}
}
var documentXML = new DOMParser().parseFromString(conteudoXML.join("\n"),"text/xml");
var nodos = documentXML.getElementsByTagName("nodo");
for (var indice = 0; indice < nodos.length; indice++) {
var nodo = nodos[indice];
console.log(nodo.getAttribute("name"));
}
EDIT: The solutions below were attempts to reply when the questioner did not give enough data, I will kill them because they are interesting.
If you want to work with plain text, you can search for the occurrence of the text "node name=" and then retrieve the next value that is enclosed in quotation marks.
var responseText = '\
String (46)=> "name=""nome""/string" \
String (58)=> "nodo name=""documento""/html" \
String (35)=> "idade""40""qualquercoisa" \
String (43)=> "nodo name=""hoje""algoaqui" \
';
function encontrarValores(string, chave, separador, delimitador){
var indice = string.indexOf(chave, 0);
var valores = [];
do {
var iniIndice = indice + chave.length + separador.length + delimitador.length;
var fimIndice = string.indexOf(delimitador, iniIndice);
var valor = string.substring(iniIndice, fimIndice);
valores.push(valor);
indice = string.indexOf(chave, indice + 1);
} while (indice >= 0);
return valores;
}
var valores = encontrarValores(responseText, 'nodo name', '=', '""')
console.log(valores);
However, if you were working with HTML, you could simply do the following:
var responseText = '\
<div nodo="externa">\
<div nodo="interna 1">Interna 1</div>\
<div nodo="interna 2">Interna 2</div>\
<div nodo="interna 3">Interna 3</div>\
</div">\
';
var container = document.createElement("div");
container.innerHTML = responseText;
var elements = container.querySelectorAll("[nodo]");
for (var indice in elements) {
var element = elements[indice];
if (element.nodeType == 1) {
console.log(element.getAttribute("nodo"));
}
}