加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用正则表达式从序列中分割字符串

发布时间:2020-12-14 05:55:49 所属栏目:百科 来源:网络整理
导读:我需要一个匹配字母和数字的正则表达式,但不匹配序列“00”. 例如“hello00world00number001”应匹配:“hello”,“world”,“number”和“1”. 我测试没有成功: (?:[w](?!00))+ 编辑:“hello000world0000number000001”必须分为:“hello0”“world”“n
我需要一个匹配字母和数字的正则表达式,但不匹配序列“00”.

例如“hello00world00number001”应匹配:“hello”,“world”,“number”和“1”.

我测试没有成功:

(?:[w](?<!00))+

编辑:“hello000world0000number000001”必须分为:“hello0”“world”“number0”和“1”

解决方法

输入字符串:hello000world0000number00000100test00test20

分裂

>如果遇到类似0000的系列,则仅按00分割将生成空匹配:
输出:hello / 0world // number // 01 / test / test20
>要解决此问题,请在组中包含2个零:
RegEx:(00) – 系列中的最后一个不均匀0进入下一场比赛–live demo
输出:hello / 0world / number / 01 / test / test20
>使用否定前瞻:
RegEx:(00)(?!0) – 在第一场比赛中保持第0个不均匀系列 – live demo
输出:hello0 / world / number0 / 1 / test / test20

比赛

>仅00的结果不正确
> /([a-z0-9]?)(?:(?:00)| $)/ gi – live demo
> /([a-z0-9]?)(?:(?:00)(?!0)| $)/ gi – live demo

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读