谁能告诉我为什么以下不起作用?:
小提琴:http: //jsfiddle.net/anderslyman/86NHs/
JavaScript:
var value = 'lorem ipsum dolor sit amet';
var wordLength = 11;
var find = new RegExp('\b[a-zA-Z]{2,' + wordLength + '}\b');
console.log(value.match(find));
console.log(value.match(/\b[a-zA-Z]{2,11}\b/));
我希望这两个console.log()
语句都输出相同的东西,因为正则表达式是相同的......