替换

通过一些例子来学习正则表达式摘录,js正则函数match、exec、test、search、replace、split

去除首尾的

//去除首尾的‘/’input=input.replace(/^\/*|\/*$/g,'');

javascript:;、javascript:void(0)

'javascript:;'.match(/^(javascript\s*\:|#)/);//["javascript:","javascript:",index:0,input:"javascript:;"]

匹配

varstr="access_token=dcb90862-29fb-4b03-93ff-5f0a8f546250;refresh_token=702f4815-a0ff-456c-82ce-24e4d7d619e6;account_uid=1361177947320160506170322436";str.match(/account_uid=([^\=](\;)|(.*))/ig);

匹配一些字符

varstr='asdfhtml-webpack-pluginfor"index/index.html"asdfasdf';str.match(/html-webpack-pluginfor\"(.*)\"/ig);console.log(RegExp.$1)//=