正则表达的一些基础练习

表达字符串

Is is the cost of of gasoline going up up chapterasdfasdfasdf 12.5 abasdfgsdwertwer filename.text ding.text nkkaj.text chapter1 chapter2 chapter3 chapter4 chapter- chapter* asdf aASDFASD asd aod apdkjsh aKJHAJKd32.4,aksdlkj,~/-+@#$%^& Section2 Section3 2107-12-01 2016-2-99 Section4Section6chapter21chapter05chapter 15654 121.3 65453.5 545.2 asd f31351.23456.34156 0.235 0

匹配字符串 a: /a/

匹配一次或多次 a: /as+/

匹配0次或多次 a: /as*/

匹配 a[任意字符]d 的字符串: /a.d/

匹配 a[非指定字符串]d : / a[^s]d/

匹配 a[0~10个任意字符串]d: /a(.{0,10})d/

匹配 a[0~10个任意字符串]d 非贪婪模式: /a(.{0,10}?)d/

匹配 a[0~10个任意字符串,除了s字符外]d : /a(.{0,10}[^s])d/

匹配 a[0~10个任意小写字符串]d : /a(.[a-z]{0,10})d/

匹配 [!~-] 的字符 : /[!–]/

匹配开头处字符串: /^chapter/

匹配结尾处字符串: /chapter$/

匹配 [chapter与section中 1-5 部分]: /(chapter|Section)[1-5]/

匹配 chapter1,chapter2,chapter3之外的chapter: /chapter[^123]/

匹配有两位数的 chapter : /chapter[0-9][0-9]{0,1}/

匹配 大小写,数字的字符 : /[A-Za-z0-9]/

匹配出现次数大于: /\b([a-z]+) \1\b/ (注:表达式会将正则中的“()”里面的内容储存到一个临时缓冲区中,从左到右 这里的缓冲区里储存的就是“([a-z]+)” )

匹配其中所有的正负数包括小数: /-?\d+(.\d+)?/

匹配其中所有的日期: \d{0,4}-(\d[1-2]|[1-12])-([0-3]\d|\d)

匹配9-14位大小写包括下划线 字符串: \w{9,14}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值