正则表达式

资料参考:正则表达式

1、匹配指定字符串开始,例如:

const str1 = "LITERALLY CAN'T EVEN";
const str2 = "FIGURATIVELY can't even";
const str3 = "litERALLY whatever"

const reg = /^LITERALLY/

console.log(reg.test(str1)) // true
console.log(reg.test(str2)) // false
console.log(reg.test(str3)) // false

2、匹配指定字符串结束,例如:

const str1 = "THIS SHIITAKE IS BANANAS";
const str2 = "BANANAS";
const str3 = "NOTHING";

const reg = /BANANAS$/;

console.log(reg.test(str1)); // true
console.log(reg.test(str2)); // true
console.log(reg.test(str3)); // false

3、匹配开头非数字,第二个字符非大写字母,例如:

const str1 = "1A";
const str2 = "A1";
const str3 = "ABC";
const str4 = "abc";
const str5 = "555";
const str6 = "5z";
const str7 = "...";

const reg = /^\D[^A-D]/;

console.log(reg.test(str1)); // false
console.log(reg.test(str2)); // true
console.log(reg.test(str3)); // false
console.log(reg.test(str4)); // true
console.log(reg.test(str5)); // false
console.log(reg.test(str6)); // false
console.log(reg.test(str7)); // true

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值