【发布时间】:2020-04-17 06:14:20
【问题描述】:
相同的正则表达式,不同的结果;
Java
String regex = "Windows(?=95|98|NT|2000)";
String str = "Windows2000";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
System.out.println(m.matches()); // print false
JavaScript
var value = "Windows2000";
var reg = /Windows(?=95|98|NT|2000)/;
console.info(reg.test(value)); // print true
我不明白为什么会这样?
【问题讨论】:
-
这可能是因为
matches()在要测试的 whole 字符串匹配时返回 true。 (积极的前瞻不是匹配的一部分)
标签: javascript java regex