Javascript正则表达式引擎类型的测试
本次测试的使用的是nodejs、chrome、firefox和ie,由于这四个所表示的结果一致,所以只贴出来同一个测试结果。
1.忽略优先量词测试
var res = '123456'.match(/\d{3,5}/);console.log(res);var res = '123456'.match(/\d{3,5}?/);console.log(res);
[ '12345', index: 0, input: '123456' ][ '123', index: 0, input: '123456' ]
var res = 'nfa not'.match(/nfa|nfa not/);console.log(res);
[ 'nfa', index: 0, input: 'nfa not' ]
String.prototype.trim = function(){ return this.replace(/^\s*(.*?)\s*/, function($1, $2){ return $2; });};