数据匹配之正则表达式

先来了解一下各字符代表的意思:
\d :digit(0-9) 数字0-9
\D :not a digit 非数字
\w :word character(a-z,A-Z,0-9,_) 大小写字母数字下划线
\W :not a word character 大小写字母数字下划线以外
\s :whitespace(space,tab,blank,line) 空格、tab。。
\S :non_whitespace 非空格

\b :word boundary
\B :not a word boundary
\A :start of string 表示开头,也可以用^
\Z :end of string 表示结尾,也可以用$
\g

\ :escape special character 转意符,加上\之后表示该字符本身
. :Matches any characters 匹配任意字符
$ :matches end of string 匹配结尾
^ :matches beginning of string 匹配开头
[] :matches characters in brackets 匹配[]里的任意一个字符
[^] :matches characters not in brackets 匹配[]以外的字符
| :Either or 或
() :group 分组

“*” :0 or more 匹配0次或多次
“+” :1 or more 匹配1次以上
? :0 or 1 匹配0次或1次
{m} :exactly m times 匹配m次
{n,} :min n times 匹配至少n次
{m,n} :from m to n times 匹配m次到n次
{m,n}?:from m to n,as few as possible 匹配m次到n次之间尽量少的次数

下面是练习部分:
1、匹配以1开头的电话号码:1xx-xxxx-xxxx
1\d{2}(-\d{4}){2}
2、匹配邮箱:
1[\w.-]+@[a-zA-Z0-9][\w.]{2,}


  1. a-zA-Z0-9 ↩︎

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值