V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
gouera
V2EX  ›  Linux

关于正则表达式的问题。

  •  
  •   gouera · 2013-10-22 19:06:27 +08:00 · 2785 次点击
    这是一个创建于 3844 天前的主题,其中的信息可能已经有所发展或是发生改变。
    [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 条回复    1970-01-01 08:00:00 +08:00
    bluntblade
        1
    bluntblade  
       2013-10-22 19:15:06 +08:00
    sed -n '/[0-9]\{6\}/p' a.txt
    9hills
        2
    9hills  
       2013-10-22 19:18:00 +08:00
    大括号要转义

    sed -n '/[0-9]\{6\}/p' a.txt
    foru17
        3
    foru17  
       2013-10-22 19:20:17 +08:00
    你是要匹配长度为6位的这些数字吧?
    ^[0-9]{6}$
    gouera
        4
    gouera  
    OP
       2013-10-22 19:26:27 +08:00
    @9hills 啊。我懂了,忘记了。 谢谢你啊。
    rrfeng
        5
    rrfeng  
       2013-10-22 19:38:10 +08:00
    @gouera
    或者 sed -r {} 就不需要转义了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1814 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 00:52 · PVG 08:52 · LAX 17:52 · JFK 20:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.