Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
142
rated 0 times [  145] [ 3]  / answers: 1 / hits: 19713  / 8 Years ago, tue, june 14, 2016, 12:00:00

Having trouble with very simple thing,
How to properly replace all < br> and <br> in the string with the empty space?



This is what I'm trying to use, but I'm receiving the same string.:



var finalStr = replaceAll(replaceAll(scope.ItemsList[i].itemDescr.substring(0, 27), <,  ), br>,  );
function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace);
}

More From » regex

 Answers
7

You can achieve that using this:


str = str.replace(/<brs*/?>/gi,' ');

This will match:



  • <br matches the characters <br literally (case insensitive)

  • s* match any white space character [rntf ]

  • Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]

  • /? matches the character / literally

  • Quantifier: ? Between zero and one time, as many times as possible, giving back as needed [greedy]

  • > matches the characters > literally

  • g modifier: global. All matches (don't return on first match)

  • i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])


SNIPPET BELOW




let str = This<br />sentence<br>output<BR/>will<Br/>have<BR>0 br;
str = str.replace(/<brs*/?>/gi, ' ');
console.log(str)




[#61774] Sunday, June 12, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckaylab

Total Points: 311
Total Questions: 120
Total Answers: 93

Location: Montenegro
Member since Thu, Jun 16, 2022
2 Years ago
;