如何从字符串中删除所有 <br> 标签

我有一个大绳子


Hello<br>I am a On then sake home is am leaf<br> Of suspicion do departure at extremely he 

believing.<br> Do know said mind do rent they oh hope of <br> General enquire picture letters garrets on

offices of no on<br> Say one hearing between excited evening all inhabit thought you<br> Style begin mr

heard by in music tried do<br> To unreserved projection no introduced invitation<br> .... 1200 words.

<br>现在我想用“”替换那些标签。我不知道正则表达式,有人可以帮我吗?而且我使用了 javascript 字符串替换,但没有用。


蝴蝶不菲
浏览 98回答 1
1回答

海绵宝宝撒

替换<br>常规空间" "。const yourString = "Hello<br>I am a On then sake home is am leaf<br> Of suspicion do departure at extremely he believing.<br> Do know said mind do rent they oh hope of <br> General enquire picture letters garrets on offices of no on<br> Say one hearing between excited evening all inhabit thought you<br> Style begin mr heard by in music tried do<br> To unreserved projection no introduced invitation<br>"const result = yourString.replace(/<br>/gi," ")&nbsp; &nbsp; &nbsp; // REPLACES ALL <br> OCCURRENCES FOR A REGULAR SPACE.replace(/\s+/g," ")&nbsp; &nbsp; &nbsp; &nbsp; // REPLACES POSSIBLE MULTIPLE SPACES FOR A SINGLE SPACE.trim();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // REMOVES POSSIBLE SPACES FROM THE BEGINNING AND END OF THE STRING&nbsp;&nbsp;console.log(result);替换<br>常规的新行"\n"。const yourString = "Hello<br>I am a On then sake home is am leaf<br> Of suspicion do departure at extremely he believing.<br> Do know said mind do rent they oh hope of <br> General enquire picture letters garrets on offices of no on<br> Say one hearing between excited evening all inhabit thought you<br> Style begin mr heard by in music tried do<br> To unreserved projection no introduced invitation<br>"const result = yourString.replace(/<br>\s*/gi,"\n")&nbsp; &nbsp; &nbsp; // REPLACES ALL <br> FOLLOWED BY 0 OR MORE SAPCES FOR A NEW LINE.trim();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // REMOVES POSSIBLE SPACES FROM THE BEGINNING AND END OF THE STRING&nbsp;&nbsp;console.log(result);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript