简体   繁体   中英

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

I have a big string like

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.

Now I want to replace those <br> tags with " ". I don't know regex, can someone please help me ? And I used javascript string replace and it didn't work.

Replacing <br> for regular space " " .

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

Replacing <br> for regular new lines "\\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);

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