Skip to content Skip to sidebar Skip to footer

Deleting Everything After A Character With Javascript Regex

Charlie Wilson's War (2007) For my stuff above, I can't figure out a Javascript Regex pattern to delete

Solution 1:

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

Solution 2:

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));

Post a Comment for "Deleting Everything After A Character With Javascript Regex"