有没有使用Java和JS中的正则表达式\b的区别?
我进行了以下测试:
在JavaScript中:
为什么上述两个例子的结果不同?
我进行了以下测试:
在JavaScript中:
console.log(/\w+\b/.test("test中文"));//true
在Java中:
String regEx = "\\w+\\b";
text = "test中文";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(text);
while(matcher.find()) {
System.out.println("matched");//never executed
}
为什么上述两个例子的结果不同?