什么似乎是正确的正则表达式在替换函数中不起作用(What seems to be a correct regex doesn't work in replace function)
我试图匹配三个连续的点(“。”),然后选择一个空格。
我的想法如下:
\.\.\.\s?在这里进行了测试 ,似乎完全符合预期。
但是当我尝试在javascript的替换函数中使用它时它似乎不起作用,除非我遗漏了一些愚蠢的东西,否则它很奇怪:
replace("\.\.\.\s?", "")不起作用,请看这里的现场演示 。
我错过了什么?
I am trying to match three consecutive dots (".") followed optionally by a space.
My idea was the following:
\.\.\.\s?Tested it here and seems to do exactly as expected.
But then when I try to use it in the replace function with javascript it doesn't seem to work, it's quite weird unless I'm missing something silly:
replace("\.\.\.\s?", "")Doesn't work, see live demo here.
What am I missing?
最满意答案
正则表达式不应该在引号中。 尝试...
mystr.replace(/\.\.\.\s?/, "")的jsfiddle
The regex shouldn't be in quotes. Try...
mystr.replace(/\.\.\.\s?/, "")jsfiddle
更多推荐
发布评论