简体   繁体   English

为什么javascript替换方法(没有正则表达式)在angularjs表达式中不起作用以删除?

[英]Why does javascript replace method (without regex) doesnt work in angularjs expression to remove &nbsp?

The SO link Javascript Regular expression to remove unwanted <br>, &nbsp; SO链接Javascript正则表达式去除不需要的<br>、&nbsp; sp tells us to remove an expression using regex.But i want to remove &nb sp; sp 告诉我们使用正则表达式删除表达式。但我想删除 &nb sp; without using regex.Angular expression:不使用 regex.Angular 表达式:

{{notification.noti_val)}};Did:{{notification.noti_val.replace(/\&nb sp;/g, ' ')}}

.But doesnt delete the &nb sp; .但不删除&nb sp;

Note:did a space between nb and sp cause SO was parsing it as whitespace so was showing it as whitespace注意:nb 和 sp 之间是否有空格导致 SO 将其解析为空格,因此将其显示为空格

Use \\s* instead of a literal space character.使用\\s*而不是文字空格字符。 \\s should match any kind of whitespace character. \\s应该匹配任何类型的空白字符。 Adding * next to \\s should match any kind of space zero or more times.\\s旁边添加*应该匹配任何类型的空格零次或多次。

noti_val.replace(/\&nb\s*sp;/g, ' ')

Note that this would replace &nbsp;请注意,这将替换&nbsp; with a space character.带有空格字符。 If you want to remove then replace it with empty string.如果要删除,则将其替换为空字符串。

noti_val.replace(/\&nb\s*sp;/g, '')

DEMO演示

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

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