Kaj
Kaj

Reputation: 2503

Regex html tag data

I'm getting (HTTP request) and I'm trying to get certain data out of it by using a regex, for example this part of the HTML:

<tr><th>Continent:</th><td class='trc'>Europe (EU)</td></tr>

How can I get the 'Europe (EU)' out of this?

I've tried this regex:

/<th>Continent:<\/th><td class='trc'>(.+)\s<\/td>/

But this does not work

Upvotes: 0

Views: 189

Answers (1)

melwil
melwil

Reputation: 2553

You are telling the regex to look for a space followed by </td>

/<th>Continent:<\/th><td class='trc'>(.+)\s<\/td>/  
                                         ^^

I'd recommend using [^<>]+ to search for text between html tags.

/<th>Continent:<\/th><td class='trc'>([^<>]+)<\/td>/

Upvotes: 2

Related Questions