Eye*_*Eye 0 javascript regex node.js
我正在使用Node v.0.8.8.
在以下示例中,为什么url与/([\w-]+)正则表达式不匹配?这是一个错误还是我做错了什么?
var patterns = [
'/([\w-]+)',
'/.*'
],
url = '/asdf';
for (var pattern in patterns) {
var re, match;
re = new RegExp('^' + patterns[pattern] + '$');
if ((match = re.exec(url))) {
console.log(url + ' matched: ' + patterns[pattern])
// break the loop since we've already found the first match
return false;
}
else{
console.log(url + ' NOT matched: ' + patterns[pattern])
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
88 次 |
| 最近记录: |