1、将某一个字符串的后缀名后面加上“!400_500”
使用场景是将minio拿过来的图片压缩尺寸从而压缩其大小,加快渲染的速度。需要在图片的后缀名后面加上尺寸如下:
javascript">const str = '//storage-test.test.shiqiao.com/gateway/common/isopen/2024/10/09/e708e9d012c74478b36c5ab79146f603.png?AASDDFGG';
const regex = /(\.png|\.jpg|\.jpeg)$/;
const newStr = str.replace(regex, '$1!400_500');
console.log(newStr)
//storage-test.test.shiqiao.com/gateway/common/isopen/2024/10/09/e708e9d012c74478b36c5ab79146f603.png!400_500?AASDDFGG
2、手机号校验
javascript">const mobileReg = /^1([3-9])\d{9}$/;
const phone = '1820221'
if (!mobileReg.test(phone)) {Toast('请核对手机号是否正确!');return
}
3、身份证号
javascript">const idNumberReg = /^(\d{18,18}|\d{15,15}|\d{17,17}X)$/i;
const idNumber = '1202251998090977'
if (!idNumberReg.test(idNumber)) {Toast('请核对身份证号是否正确!');return
}
总结:
javascript">/i (忽略大小写)
/g (全文查找出现的所有匹配字符)
/m (多行查找)
/gi(全文查找、忽略大小写)
/ig(全文查找、忽略大小写)