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

正则表达式 – 使用正则表达式从数字范围中排除某些数字

发布时间:2020-12-14 06:03:32 所属栏目:百科 来源:网络整理
导读:有人可以帮助我使用正则表达式,我们可以从一系列数字中排除某些数字. 目前,^([1-9] [0] [0-9])$是配置的正则表达式.现在,如果我想从中排除一些数字/一个数字(501,504),那么正则表达式将如何显示. 解决方法 更详细地描述 in this answer,您可以使用以下正则表
有人可以帮助我使用正则表达式,我们可以从一系列数字中排除某些数字.

目前,^([1-9] [0] [0-9])$是配置的正则表达式.现在,如果我想从中排除一些数字/一个数字(501,504),那么正则表达式将如何显示.

解决方法

更详细地描述 in this answer,您可以使用以下正则表达式与“负面先行”命令?!:

^((?!501|504)[0-9]*)$

你可以看到正在执行的正则表达式&这里解释:https://regex101.com/r/mL0eG4/1

  • /^((?!501|504)[0-9]*)$/mg
    • ^ assert position at start of a line
    • 1st Capturing group ((?!501|504)[0-9]*)
      • (?!501|504) Negative Lookahead – Assert that it is impossible to match the regex below
        • 1st Alternative: 501
          • 501 matches the characters 501 literally
        • 2nd Alternative: 504
          • 504 matches the characters 504 literally
      • [0-9]* match a single character present in the list below
        • Quantifier: * Between zero and unlimited times,as many times as possible,giving back as needed [greedy]
        • 0-9 a single character in the range between 0 and 9
    • $assert position at end of a line
    • m modifier: multi-line. Causes ^ and $to match the begin/end of each line (not only begin/end of string)
    • g modifier: global. All matches (don’t return on first match)
  • (编辑:李大同)

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

      推荐文章
        热点阅读