regExp 基础教程
标签:
JavaScript
<script>
/*匹配符号(- 中划线)*/
let reg = /^5-3$/;
console.log(reg.test('5-3'));
/*匹配符号(下划线 _ )*/
let reg = /^5_3$/;
console.log(reg.test('5_3'));
</script>
<script>
/*只能匹配一位数字,不是多个*/
let reg = /^\d$/;
console.log(reg.test('1'))
</script>
<script>
/*匹配一或多数字*/
let reg =/^\d+$/;
console.log(reg.test('19845'));
</script>
<script>
/*在这里点符号,转换了普通的字符,原来的点符号是,包含除了换行符号以外的数字*/
let reg = /^2\.3$/;
console.log(reg.test('2+3'));
</script>
<script>
/*匹配18或19*/
let reg = /^(18|19)$/;
console.log(reg.test('18'));
</script>
<script>
/*有四组,2便是同样匹配组的号码,第2个组和第三个组同样*/
let reg = /^([a-z])|([0-9])\2([a-z])$/;
console.log(reg.test('a55f'));
</script>
<script>
let reg = /^(\w+)([\w-]*)([\w])$/;
console.log(reg.test('asd----asd'));
</script>
<script>
/*验证18-65之间的年龄*/
let reg = /^((18|19)|([2-5]\d)|(6[0-5]))$/;
console.log(reg.test('59'));
/*
18 68
18 19
20 59
60 68
*/
/*或运算符的意思是,可以出现任意一个,匹配任意的一个组件模块*/
let reg = /^((18)|19)|([2-5]\d)|(6[0-8])$/;
console.log(reg.test('57'))
</script>
<script>
/*判断整数*/
/*
-12
12
12.5
*/
let reg = /^(-)?(\d+)((\.\d+)?)$/;
console.log(reg.test('12.65'));
</script>
<script type="text/javascript">
/*
oppo_A83@163.com
oppo (([a-z])|([A-Z])|(\d))+
_ ((-|_)?)
A83 (([a-z])|([A-Z])|(\d))+
@ @{1}
163 (([a-z])|([A-Z])|(\d))+
*/
/*oppo_A83 let reg = /^(([a-z])|([A-Z])|(\d))+((-|_)?)$/;*/
/*oppo_A83 let reg = /^(([a-z])|([A-Z])|(\d))+((-|_)?)((([a-z])|([A-Z])|(\d))+)?
/*oppo_A83@ let reg = /^(([a-z])|([A-Z])|(\d))+((-|_)?)(([a-z])|([A-Z])|(\d))+@{1}$/;*/
/*oppo_A83@163 let reg = /^(([a-z])|([A-Z])|(\d))+((-|_)?)(([a-z])|([A-Z])|(\d))+@{1}(([a-z])|([A-Z])|(\d))+$/;*/
/*oppo_A83@163 let reg = /^(([a-z])|([A-Z])|(\d))+((-|_)?)(([a-z])|([A-Z])|(\d))+@{1}(([a-z])|([A-Z])|(\d))+(\.)(([a-z])|([A-Z])|(\d))+$/;*/
let reg = /^(([a-z])|([A-Z])|(\d))+((-|_)?)((([a-z])|([A-Z])|(\d))+)?@{1}(([a-z])|([A-Z])|(\d))+(\.)(([a-z])|([A-Z])|(\d))+$/;
console.log(reg.test('oppo_A83@163.com'));
</script>
<script>
/*
*
* 1959 2018
*
* 1959 1999
* 2000 2009
* 2010 2018
*
* */
let reg=/^(19[5-9]9)|(200\d)|(201[0-8])$/;
console.log(reg.test('2015'));
</script>
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦