关于区间表达式的使用

1836阅读 0评论2012-02-29 linux_kaige
分类:Python/Ruby

1.从百度百科查看到:
  1. {i}
  2. {i,j} 匹配指定数目的字符,这些字符是在它之前的表达式定义的。例如正则表达式A[0-9]{3} 能够匹配字符"A"后面跟着正好3个数字字符的串,例如A123、A348等,但是不匹配A1234。而正则表达式[0-9]{4,6} 匹配连续的任意4个、5个或者6个数字字符。注意:这个元字符不是所有的软件都支持的。
2.测试:
  1. [yangkai@admin awkdir]$ cat filea |awk '/[0-9]{3,}/'
  2. [yangkai@admin awkdir]$ cat filea |awk --re '/[0-9]{3,}/'
  3. 10/05766798607,11/20050325191329,29/0.1,14/05766798607
  4. 10/05767158557,11/20050325191329,29/0.08,14/05767158557
  5. [yangkai@admin awkdir]$ grep "[0-9]{5}"
  6. [yangkai@admin awkdir]$ grep "[0-9]{5}" filea
  7. [yangkai@admin awkdir]$ egrep "[0-9]{5}" filea
  8. 10/05766798607,11/20050325191329,29/0.1,14/05766798607
  9. 10/05767158557,11/20050325191329,29/0.08,14/05767158557
  10. [yangkai@admin awkdir]$ grep -E "[0-9]{5}" filea
  11. 10/05766798607,11/20050325191329,29/0.1,14/05766798607
  12. 10/05767158557,11/20050325191329,29/0.08,14/05767158557
  13. [yangkai@admin awkdir]$
3.man awk:
  1. -W re-interval
  2. --re-interval
  3. Enable the use of interval expressions in regular expression matching (see Regular Expressions, below).
  4. Interval expressions were not traditionally available in the AWK language. The POSIX standard added them, to
  5. make awk and egrep consistent with each other. However, their use is likely to break old AWK programs, so
  6. gawk only provides them if they are requested with this option, or when --posix is specified.
4.不是所有软件都适用。。。




上一篇:NoSQL数据库
下一篇:分布式文件系统:原理、问题与方法