On web page like this
<div>text text</div> |text text 55.555555 |44.444444 | <div>text <b>name</b></div>
I need to get array like this
{ [55.555555 , 44.444444, "name"] , [ ... , ... , ... ], ... }
I would like to use regular expressions to achieve the - find coordinates part, but I don't know how to write this part:
return all text parts which match this expression
Can you help me with some ideas / functions?
UPDATE
I found nativeTreeWalker function here get all text nodes / SO and I changed this function to look for 2 numbers and a text. This pretty much works, but I still have a bug, it returns even numbers like 1234 .. with no decimal.
function nativeTreeWalker() {
var walker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_TEXT,
null,
false
);
var node;
var textNodes = [];
var name = false;
var elem = null;
while(node = walker.nextNode()) {
if (name){ elem.push(node.nodeValue); textNodes.push(elem); console.log(elem); name = false; }
else { elem = null; }
elem = node.nodeValue.match(/\d{2}.\d+/g);
if (elem!=null){ name=true; }
}
}
nativeTreeWalker()