我想使用以下nodejs函数来检查我的字符串中是否存在特定种类的url。我单独检查了这个正则表达式,看起来不错,但是在节点中给我一个错误。无法获得有效的正则表达式在nodejs中工作
var checkforURL = function(data) {
var re = /((?:https?://)?www\.example\.com\/tp\/\S+\d+)/g/;
return re.test(data);
}
这应该为以下情况
等等等等 返回true
当我尝试运行代码时,我收到以下编译错误 var re = /((??https?://www.example.com/tp/\S+\d+)/g/; ^
SyntaxError: Unexpected token) at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:906:3
我需要这个括号,它们包围的https://,以确保它可以存在0或1的时候,不知道为什么不断的NodeJS抛出一个错误,任何想法?
+1
你需要躲避向前'的https斜杠://',你也需要删除最后一个'/'后克 –
2014-09-03 02:32:58
+0
就是那个'example'或'exmaple'? –
2014-09-03 02:36:54