简体   繁体   中英

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; sp tells us to remove an expression using regex.But i want to remove &nb sp; without using regex.Angular expression:

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

.But doesnt delete the &nb sp;

Note:did a space between nb and sp cause SO was parsing it as whitespace so was showing it as whitespace

Use \\s* instead of a literal space character. \\s should match any kind of whitespace character. Adding * next to \\s should match any kind of space zero or more times.

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

Note that this would replace &nbsp; with a space character. If you want to remove then replace it with empty string.

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

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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