1.必须包含大小写数字 8-16位
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z0-9]{8,16}$/复制代码
2.数字千分位展示
function numberWithCommas(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");}复制代码
3.转义需要转义的
function escapeRegexp(queryToEscape) { return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1')}复制代码
4. 连字符转驼峰 ad-bd-cd to adBdCd
var camelizeRE = /-(\w)/g;var camelize = function (str) { return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; })}复制代码
5.驼峰转连字符
var hyphenateRE = /\B([A-Z])/g;var hyphenate = function (str) { return str.replace(hyphenateRE, '-$1').toLowerCase()};复制代码
6.转义html
function htmlEscape(text){ return text.replace(/[<>"&]/g, function(match, pos, originalText){ console.log(match, pos, originalText) switch(match){ case "<": return "<"; case ">":return ">"; case "&":return "&"; case "\"":return """; } });}复制代码
7.判断相对 绝对路径
var absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/;var relativePath = /^\.?\.\//;function isAbsolute(path$$1) { return absolutePath.test(path$$1);}function isRelative(path$$1) { return relativePath.test(path$$1);}复制代码