Reputation: 1
Charlie Wilson's War
<span class="nobr">(<a href="/year/2007/">2007</a>)</span>
For my stuff above, I can't figure out a Javascript Regex pattern to delete < and everything after so I can get only the title. This must be easy.
Upvotes: 0
Views: 218
Reputation: 25332
A regexp pattern could be [^<]+
, therefore:
var string = "Charlie Wilson's War<span class=\"nobr\">(<a href=\"/year/2007/\">2007</a>)</span>";
var re = /[^<]+/;
console.log(string.match(re));
Upvotes: 0
Reputation: 43703
var html = 'Charlie Wilson\'s War<span class="nobr">...</span>';
console.log(html.split('<')[0]);
Upvotes: 1