亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從字符串中刪除所有 <br> 標簽

如何從字符串中刪除所有 <br> 標簽

蝴蝶不菲 2023-06-09 17:24:01
我有一個大繩子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 onoffices of no on<br> Say one hearing between excited evening all inhabit thought you<br> Style begin mrheard by in music tried do<br> To unreserved projection no introduced invitation<br> .... 1200 words.<br>現在我想用“”替換那些標簽。我不知道正則表達式,有人可以幫我嗎?而且我使用了 javascript 字符串替換,但沒有用。
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻1809條經驗 獲得超8個贊

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


查看完整回答
反對 回復 2023-06-09
  • 1 回答
  • 0 關注
  • 162 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號