[英]Javascript replace html tags with blank string
I am trying to replace all the /n, <br>
and space
in the string and replace them with ''
. 我正在尝试替换字符串中的所有
/n, <br>
和space
,并用''
替换它们。
My approach is using replace
. 我的方法是使用
replace
。 However, I am getting the following errors. 但是,我收到以下错误。
Uncaught SyntaxError: Unexpected string
I know 我知道
console.log(text.value[langID]) would output bunch of texts.
but I got the error when I changed my codes to this. 但是我将代码更改为此时遇到了错误。
console.log(text.value[langID].replace('/\n|<br>|\s/g', ''));
I am not sure what went wrong here and if my rex pattern can filter my requirements. 我不确定这里出了什么问题以及我的rex模式是否可以过滤我的需求。
Can anyone gives me a hint? 谁能给我一个提示?
Thanks so much! 非常感谢!
You missed the comma separator for replace
parameters. 您错过了
replace
参数的逗号分隔符。 Also, as @Ingo Bürk pointed out, quotes for regex expression are not valid so you have to remove them too 另外,正如@IngoBürk所指出的,正则表达式的引号无效,因此您也必须将其删除
console.log(text.value[langID].replace(/\n|<br>|\s/g,''));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.