簡體   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