morri
V2EX  ›  问与答

请问这个正则要怎么写呢?

  •  
  •   morri · Dec 31, 2022 · 2439 views
    This topic created in 1402 days ago, the information mentioned may be changed or developed.

    字符串如下:

     1933 the sneaking10 around, she said, was distressing11. 
    

    我要匹配以字符串开始数字结尾的子串中的数字。 10和11, 单独的 1933 不用匹配。

    现在 [a-z]+\d+ 可以匹配到 sneaking10和 distressing11

    如何在这个的基础上在匹配数字呢?

    9 replies  •  2023-01-01 16:43:33 +08:00
    darer
    darer
    Dec 31, 2022
    1
    要用断言咧
    Boyce
    Boyce
    Dec 31, 2022
    2
    [a-z]+(\d+)
    darer
    darer
    Dec 31, 2022❤️1
    3
    (?<=[a-zA-Z])\d+
    morri
    morri
    OP
    Dec 31, 2022
    4
    @darer 厉害~ 这个可以匹配,断言不会呀。有好的博客推荐么,学学 😂~
    darer
    darer
    Dec 31, 2022
    5
    @morri 没必要 知道有这么个东西就行 每次用到的时候现查就好了
    morri
    morri
    OP
    Dec 31, 2022
    6
    @darer 3q
    wudicgi
    wudicgi
    Dec 31, 2022❤️1
    7
    @morri #4 我一般查的时候就看这个文档,页面中有 零宽断言 (?<=exp) 匹配 exp 后面的位置
    https://deerchao.cn/tutorials/regex/regex.htm
    Uyloal
    Uyloal
    Dec 31, 2022
    8
    试试这个行不行 https://imgur.com/a/vdhd8y5
    Nile20
    Nile20
    Jan 1, 2023
    9
    正则表达式还是孰能生巧,推荐个网站,可以在线编辑表达式并实时查看匹配效果
    https://regex101.com/
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5473 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 02:06 · PVG 10:06 · LAX 18:06 · JFK 21:06
    ♥ Do have faith in what you're doing.