简体   繁体   中英

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM