Lets say I have the following string:
var string = "<td>123</td><td>asd</td>";
I want to take the values of the td's and put them in an array. I tried using the foreach function but my regex stops after the first closing td and gets everything between < and >.
var regex = '<([^<> ]*)([^<>]*)?>([^>]*)<\/([^<>]*)>';
var string = "<td>123</td><td>asd</td>";
var result = string.match(regex);
result.forEach(function($var){
console.log($var);
});
Output:
<td>123</td>
td
undefined
123
td
I need to manipulate the values so I can work directly in the foreach function without first splitting to an array.
Can I make this work with a regex? I can't use jQuery or append the string to the html.