# 一些正则表达式
通过一些例子来学习正则表达式摘录,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:;"]
@前端进阶之旅: 代码已经复制到剪贴板
# 匹配
var str = "access_token=dcb90862-29fb-4b03-93ff-5f0a8f546250; refresh_token=702f4815-a0ff-456c-82ce-24e4d7d619e6; account_uid=1361177947320160506170322436";
str.match(/account_uid=([^\=]+(\;)|(.*))/ig);
@前端进阶之旅: 代码已经复制到剪贴板
# 匹配一些字符
var str = 'asdf html-webpack-plugin for "index/index.html" asdfasdf';
str.match(/html-webpack-plugin for \"(.*)\"/ig);
console.log(RegExp.$1) //=>index/index.html
@前端进阶之旅: 代码已经复制到剪贴板
# 关键字符替换
'css/[hash:8].index-index.css'.replace(/\[(?:(\w+):)?(contenthash|hash)(?::([a-z]+\d*))?(?::(\d+))?\]/ig,'(.*)');
//=> css/(.*).index-i