next up previous contents
Next: 基礎與延伸比較一 Up: 正規表示法 Previous: 正規表示法與萬用字元   Contents

延伸正規表示法

  1. grep 支援的是基礎型的正規表示法,延伸正規表示法 egrep 是 grep -E 的命令別名。
  2. 延伸型正規表示法之特殊符號
    RE 字符         意義與範例
      +      重複『一個或一個以上』的前一個 RE 字符
      ?     『零個或一個』的前一個 RE 字符
      |      用或( or )的方式找出數個字串
     ( )     找出『群組』字串或作為『多個重複群組』的判別
    
  3. +:找 C 後接一個以上小寫英文字母。
    [dywang@dywIssd zzz]$ grep -E 'C[a-z]+' /etc/man.config  --color
    # Certain versions of the FSSTND recommend putting formatted versions
    # Certain versions of the FHS recommend putting formatted versions of
    # Compress cat pages
    
  4. (|):找 lcoal 或 share 或 foo 字串。
    [dywang@dywIssd zzz]$ egrep '(local|share|foo)' /etc/man.config  --color
    # /usr/.../share/man/[locale/]manx/page.x into
    # /var/cache/man/.../[locale/]catx/page.x.
    # MANBIN		/usr/local/bin/man
    MANPATH	/usr/share/man
    MANPATH	/usr/local/man
    MANPATH	/usr/local/share/man
    # MANPATH	/usr/share/*/man
    # If people ask for "man foo" and have "/dir/bin/foo" in their PATH
    MANPATH_MAP	/bin			/usr/share/man
    MANPATH_MAP	/sbin			/usr/share/man
    MANPATH_MAP	/usr/bin		/usr/share/man
    MANPATH_MAP	/usr/sbin		/usr/share/man
    MANPATH_MAP	/usr/local/bin		/usr/local/share/man
    MANPATH_MAP	/usr/local/sbin		/usr/local/share/man
    MANPATH_MAP	/usr/bin/mh		/usr/share/man
    
  5. ?:找 inet 後接一個或 0 個數字 "6"。
    [dywang@dywIssd zzz]$ ifconfig | egrep 'inet6? ' --color
        inet addr:192.168.1.140  Bcast:192.168.1.255  Mask:255.255.255.0
        inet6 addr: fe80::8ad7:f6ff:fe53:3525/64 Scope:Link
        inet addr:127.0.0.1  Mask:255.0.0.0
        inet6 addr: ::1/128 Scope:Host
        inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
        inet6 addr: 2001:ac18::131/64 Scope:Global
    



De-Yu Wang 2019-08-12