繁体   English   中英

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

[英]How do I remove all the <br> tags from a string

我有一个像

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 字符串替换,但它不起作用。

<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," ") // REPLACES ALL <br> OCCURRENCES FOR A REGULAR SPACE .replace(/\\s+/g," ") // REPLACES POSSIBLE MULTIPLE SPACES FOR A SINGLE SPACE .trim(); // REMOVES POSSIBLE SPACES FROM THE BEGINNING AND END OF THE STRING 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") // REPLACES ALL <br> FOLLOWED BY 0 OR MORE SAPCES FOR A NEW LINE .trim(); // REMOVES POSSIBLE SPACES FROM THE BEGINNING AND END OF THE STRING console.log(result);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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