V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
leavic
V2EX  ›  问与答

请教一个 Sed 中正则表达式的问题

  •  
  •   leavic · Jul 7, 2014 · 2818 views
    This topic created in 4325 days ago, the information mentioned may be changed or developed.
    在一个sed的正则匹配中,我要匹配两个"%"之间的全部数字,并作为组1,
    以下写法可以:
    \%\([^\%]*\)\%
    #(所有非%的字符)

    \%\([^\D]*\)\%
    #(所有非-非数字的字符,蛋疼..)

    \%\([0-9]*\)\%
    #(所有数字字符,看起来好像精神病治好了)

    \%\([[:digit:]]*\)\%
    #([[:digit:]])还是GNU Sed标准呢,这么恶心)

    可是!
    可是为什么这样写就完蛋了?
    \%\(\d*\)\%

    \d不是表示数字的标准正则元字符吗?你Sed都支持对\D做反义了,难道不支持\d?还是我写法有问题?
    2 replies    2014-07-07 14:56:43 +08:00
    Shieffan
        1
    Shieffan  
       Jul 7, 2014   ❤️ 1
    你说对了,sed就是不支持\d
    leavic
        2
    leavic  
    OP
       Jul 7, 2014
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1021 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:30 · PVG 02:30 · LAX 11:30 · JFK 14:30
    ♥ Do have faith in what you're doing.