Replace all
tag with space in javascript

后端 未结 1 713
南方客
南方客 2021-01-12 11:42

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

This is

相关标签:
1条回答
  • 2021-01-12 12:09

    you can achieve that using this:

    str = str.replace(/<br\s*\/?>/gi,' ');
    

    This will match:

    • <br matches the characters <br literally (case insensitive)
    • \s* match any white space character [\r\n\t\f ]
      • 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

    var str = "This<br />phrase<br>output<BR/>will<Br/>have<BR>0 br";
    str = str.replace(/<br\s*\/?>/gi, ' ');
    console.log(str)

    0 讨论(0)
提交回复
热议问题