1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| var reg=new RegExp(/\w\w/); console.log(reg.exec("asdasda"));
var reg=new RegExp(/(\w)(\w)/); console.log(reg.exec("asdasda"));
var reg=new RegExp(/(\w)(\w)\2\1/); console.log(reg.exec("woow"));
var reg=new RegExp(/(\w)(\w)(\w)\2\1\2\3\2\.\w+/); console.log(reg.exec("bilibili.com"));
var reg=new RegExp(/(?:\w)(\w)(\w)(\w)\2\1\2\3\2\.\w+/); console.log(reg.exec("abilibili.com"));
var reg=new RegExp(/\w+\.(?:com)/); console.log(reg.exec("bilibili.com"));
var reg=new RegExp(/\w+\.(?!com)/); console.log(reg.exec("bilibili.com"));
var s="123"; console.log(s.match(/\d/));
var s="123"; console.log(s.replace(/\d/g,9));
var s="123"; console.log(s.replace(/\d/g,"$1$1$1"));
var s="aaaa.aaa.aaa"; console.log(s.split(/\W/));
var s="http://weichuang.com:80"; console.log(s.match(s,"(\w+):\/\/(w+)\.(w+).(w+):([\d])"));
var s="http://www.weichuang.com:80"; console.log(s.match(/(\w+):\/\/(\w*)\.(\w+)\.(\w+):(\d*)/));
var s="http://www.weichuang.com:80"; var reg=/(\w+):\/\/(\w*)\.(\w+)\.(\w+):(\d*)/; console.log(reg.exec(s));
var s="http://www.weichuang.com:80"; var reg=/(\w+|https?):\/\/(\w*)\.(\w+)\.(\w+):(\d*)/; console.log(reg.exec(s));
|
支持正则表达式的方法match,search,replace,split