如何更换& nbsp;太空? [英] How to replace   to space?

查看:76
本文介绍了如何更换& nbsp;太空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

内容是

    Hello World.

<a&nbsp;href="#"&nbsp;target=_blank>hello&nbsp;World</a>

如何替换& nbsp; 在HTML代码中,并在文本中保留其他& nbsp;

How to replace the &nbsp; in html code and keep the other &nbsp; in the text.

推荐答案

您可以尝试搜索

(?<=<[^>]*)&nbsp;

并用单个空格替换它?

这会寻找& nbsp; 内的标签(以< 开头,可能还有其他字符,但> )。

This looks for &nbsp; inside tags (preceded by a < and possibly other characters except >).

但这非常脆弱。例如,如果您在字符串/属性中包含< / > 符号,它将失败。最好避免把那些& nbsp; 首先放在错误的位置。

This is extremely brittle, though. For example, it will fail if you have </> symbols in strings/attributes. Better avoid getting those &nbsp; into the wrong locations in the first place.

这篇关于如何更换&amp; nbsp;太空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆