简体   繁体   English

如何替换`和 <br> `

[英]how to replace multiple occurrences of `&nbsp; and <br>`

how to replace multiple occurrences of &nbsp; and <br> 如何替换多次出现的&nbsp; and <br> &nbsp; and <br> at start of the string with javascript regex? &nbsp; and <br>在使用javascript正则表达式的字符串开头?

myString = myString.replace(/^(&nbsp;|<br>)+/, '');

... where / ... / denotes a regular expression, ^ denotes start of string, ($nbsp;|<br>) denotes " &nbsp; or <br> ", and + denotes "one or more occurrence of the previous expression". ...,其中/ ... /表示正则表达式, ^表示字符串的开头, ($nbsp;|<br>)表示“ &nbsp; <br> ,而+表示“前一个或多个出现表达”。 And then simply replace that full match with an empty string. 然后只需用空字符串替换完全匹配项即可。

Check this link , this is about string replace in javascript using regular expression and normal method. 检查此链接 ,这是有关使用正则表达式和常规方法在javascript中替换字符串的信息。

Hope helpful. 希望对您有所帮助。

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

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