RegExp
去除空格并将其后的第一个字母大写
function capitalizeAfterSpace(str) { return str .replace(/^\s+|\s+(?=\s)/g, "") .replace(/
lhh|07/31/2024 14:12
RegExp
提取括号中的内容
const str = "123[abc]456{zzz}789[def]10"; // 包括括号 const reg1 = /\[(.+?)\]/g; // [] 中括号 console.log(
lhh|07/31/2024 14:11
RegExp
以最外层括号截取内容
const str = "这里是内容(括号中的内容(haha),123)"; str.split(new RegExp("\\((.*)\\)")); // ["这里是内容", "括号中的内容(hah
lhh|07/31/2024 14:11
RegExp
匹配字符串中长度大于 2 的公共元素子串
const s = "021Abc99Abc9"; if (/(.{3,}).*\1/g.test(s)) { console.log(true); }
lhh|07/31/2024 14:11
RegExp
匹配 - 和小写字符
let s = "get-ele-by"; s.replace(/-\w/g, (w) => w.slice(1).toUpperCase()); // 'getEleBy'
lhh|07/31/2024 14:11
RegExp
格式化钱
const ThousandNum = (num) => num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); const money = T
lhh|07/31/2024 14:10
RegExp
全部替换某一字符
const str = "asdfaadddqqq"; str.replace(/d/g, "-"); str.replaceAll("d", "-"); // 'as-faa---qqq'
lhh|07/31/2024 14:10
RegExp
替换最后一个逗号
let str = "a,b,c,d,"; str = str.replace(/,([^,]*)$/, "!"); // 'a,b,c,d!'
lhh|07/31/2024 14:10
RegExp
表单验证邮箱
var reg = /^([\w+\.])+@\w+([.]\w+)+$/; // \w 等价于 [^A-Za-z0-9_] // /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-
lhh|07/31/2024 14:09
博主很懒,就这么多啦~~