日期:2014-05-16 浏览次数:20332 次
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; }); };