Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
gouera
V2EX  ›  Linux

关于正则表达式的问题。

  •  
  •   gouera · Oct 22, 2013 · 3737 views
    This topic created in 4599 days ago, the information mentioned may be changed or developed.
    [0-9]这个区间然后再加上花括号{11},不是表示0-9这10个数出现11次么?

    [root@localhost ~]# cat a.txt
    121456
    1321321
    123456
    654321
    654978
    456132
    [root@localhost ~]# sed -n '/[0-9]{6}/p' a.txt
    [root@localhost ~]#
    为什么我这里会匹配不上啊, 明明感觉是对了的啊。
    求帮助
    5 replies    1970-01-01 08:00:00 +08:00
    bluntblade
        1
    bluntblade  
       Oct 22, 2013
    sed -n '/[0-9]\{6\}/p' a.txt
    9hills
        2
    9hills  
       Oct 22, 2013
    大括号要转义

    sed -n '/[0-9]\{6\}/p' a.txt
    foru17
        3
    foru17  
       Oct 22, 2013
    你是要匹配长度为6位的这些数字吧?
    ^[0-9]{6}$
    gouera
        4
    gouera  
    OP
       Oct 22, 2013
    @9hills 啊。我懂了,忘记了。 谢谢你啊。
    rrfeng
        5
    rrfeng  
       Oct 22, 2013
    @gouera
    或者 sed -r {} 就不需要转义了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4122 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 05:15 · PVG 13:15 · LAX 22:15 · JFK 01:15
    ♥ Do have faith in what you're doing.