# 判断是否为合法的 url
|  | var strUrl= "^((https|http|ftp|rtsp|mms)?://)" + | 
|  |                "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?"  | 
|  |                "(([0-9]{1,3}\.){3}[0-9]{1,3}"  | 
|  |                "|"  | 
|  |                "([0-9a-z_!~*'()-]+\.)*"  | 
|  |                "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\."  | 
|  |                "[a-z]{2,6})"  | 
|  |                "(:[0-9]{1,4})?"  | 
|  |                "((/?)|"  | 
|  |                "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; | 
|  | var urlDemo = new RegExp(strUrl);  | 
|  |  | 
|  | if(!urlDemo.test('www.baidu.com')) {  | 
|  |     this.$toast("请输入正确的url!");  | 
|  |     return;  | 
|  | } | 
# 匹配除了指定字符串的其他字符
|  |  | 
|  | www\.(?!str)[^.]+\.com | 
|  |  | 
|  | www\.(?!str1|str2|str3)[^.]+\.com | 
# 手机号格式化
当你需要将手机号码格式化成 xxx-xxxx-xxxx 的形式
|  | const formatPhone = (str, sign = '-') => str.replace(/(\W|\s)/g, "").split(/^(\d{3})(\d{4})(\d{4})$/).filter(item => item).join(sign) | 
|  |  | 
|  | formatPhone('13123456789')  | 
|  | formatPhone('13 1234 56 789', ' ')  | 
# 去除多余空格
当你需要将一段文本中的多个空格合并成一个空格
|  | const setTrimOut = str => str.replace(/\s\s+/g, ' ') | 
|  | const str = setTrimOut('hello,   jack')  | 
# 截断数字
当你需要将小数点后的某些数字截断而不取四舍五入
|  | const toFixed = (n, fixed) => `${n}`.match(new RegExp(`^-?\d+(?:.\d{0,${fixed}})?`))[0] | 
|  | toFixed(10.255, 2)  | 
# 字符串转对象
当你需要将一串字符串比如 '{name: "jack"}' 转换成对象时,直接使用 JSON.parse 将会报错。
|  | const strParse = (str) => JSON.parse(str.replace(/(\w+)\s*:/g, (_, p1) => `"${p1}":`).replace(/\'/g, "\"")) | 
|  |  | 
|  | strParse('{name: "jack"}') | 
# 颜色格式转换
当你需要将 16 进制的颜色转换成 rgb
|  | const hexToRgb = hex => hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (_, r, g, b) => `#${r}${r}${g}${g}${b}${b}`).substring(1).match(/.{2}/g).map((x) => parseInt(x, 16)); | 
|  | hexToRgb('#00ffff');  | 
|  | hexToRgb('#0ff');  |