简体   繁体   English

我怎样才能阻止正则表达式搞乱字体真棒?

[英]How can I stop regex from messing with font-awesome?

I need to hide the special character #, using regex I'm this far.我需要隐藏特殊字符#,使用正则表达式我到目前为止。 It is now removing break tags, as well as font-awesome characters, and possibly a number of other things.它现在正在删除中断标签,以及字体很棒的字符,以及其他一些可能的东西。

Any ideas?有任何想法吗?

Thanks!谢谢!

<p>#hello ## <i class="fa fa-map-marker"></i><br>secondline</p>

$("p").text(function() {
    return $(this).text().replace(/(#)/g, '');
});

Fiddle小提琴

You're using text() instead of html() so it's not your regex but it's jQuery to remove the tags您使用的是text()而不是html()所以它不是您的正则表达式,而是用于删除标签的 jQuery

$("p").html(function() {
    return $(this).html().replace(/(#)/g, '');
});

Try using .html() instead of .text() - that'll strip your HTML out:尝试使用 .html() 而不是 .text() - 这会去掉你的 HTML:

$("p").html(function() {
    return $(this).html().replace(/\#/g,'');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM