Phillip-juan
Phillip-juan

Reputation: 546

Javascript - Create a Regular Expression that gets all tags with any ID in an Array

Lets say for example I have a string:

varString = "<tr><td ID=''>Hypothyroidism</td><td ID=''>10/31/1998</td><td ID=''>Active</td><td ID=''>UNKNOWN</td><td ID=''></td></tr>";
varString += "<tr><td ID=''>Cataract</td><td ID=''>6/5/2005</td><td ID=''>Active</td><td ID=''>UNKNOWN</td><td ID=''></td></tr>";

where I then split the String into an Array like so:

var dataArray = allDataArray[x].split("</tr>");

What I'm trying is do is to use the following to get all the columns tags with content as a result. This only works for columns with an empty id:

var testRE = dataArray[x].match("<td ID=''>(.*)</td>");

Even though the following doesn't work, the format I want is something like this:

var testRE = dataArray[x].match("<td ID='(*)'>(.*)</td>");

Is there a way to still display all the data, no matter what the id is?

All knows help is appreciated.

Upvotes: 2

Views: 108

Answers (1)

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123397

try with this regexp

var testRE = dataArray[xx].match("<td ID='([^']+)?'>(.*)</td>")

Upvotes: 3

Related Questions