Deleting Everything After a Character with Javascript Regex

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

Answers (2)

ZER0
ZER0

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

Ωmega
Ωmega

Reputation: 43703

var html = 'Charlie Wilson\'s War<span class="nobr">...</span>';
console.log(html.split('<')[0]);

Upvotes: 1

Related Questions