正则表达式总结
2015-05-13 14:46
405 查看
~/.bashrc
~/.cshrc
bash: cygwin, ubuntu,
cshell: redhat
GNU: bash, make, gawk
POSIX标准
http://wenku.baidu.com/view/6194c12fcfc789eb172dc89f.html
所以
“POSIX规范的正则表达式”其实只是“关于正则表达式的POSIX规范”,它定义了BRE(Basic
Regular Expression,基本型正则表达式)和ERE(Extended Regular Express,扩展型正则表达
式)两大流派。在兼容POSIX的UNIX系统上,grep和egrep之类的工具都遵循POSIX规范,一些数据
库系统中的正则表达式也符合POSIX规范。
ANSI C与 Posix C
常见的正则表达式记法,其实都源于Perl,实际上,正则表达式从Perl衍生出一个显赫的流派,
叫做PCRE。
1. metacharacter(元字符/通配符)
. 任何单字符
* 任意0或多个字符
[aA] a或A, ^-否定,
[a-z]
^ 行开始
$ 行结尾
\{3\} 匹配3次
\{3,\} 至少匹配3次
\{3,6\} 匹配3-6次
\ 转义 \., \*, \\, \n
2. example:
[a-zA-Z][.?!]
[0-1][0-9][-/][0-3][0-9][-/][0-9][0-9] MM/DD/YY or MM-DD-YY
[^0-9]
[^aeiou]
\.DS "[^1]"
3. POSIX标准(Portable Operating System Interface for Computing Systems)
IEEE Std 1003.1 -2008
POSIX.1-2008
POSIX.1-2008 defines the Portable Operating System Interface (POSIX) requirements and
consists of the following
topics arranged as a series of volumes within the standard:
- Base Definitions
- System Interfaces
- Shell and Utilities
- Rationale (Informative)
4. 举例:
1>数据整理: 寻找"[["开头的一行数据, 结合excel进行数据处理:
$ cat trace.txt | xargs grep "^\[\["
~/.cshrc
bash: cygwin, ubuntu,
cshell: redhat
GNU: bash, make, gawk
POSIX标准
http://wenku.baidu.com/view/6194c12fcfc789eb172dc89f.html
所以
“POSIX规范的正则表达式”其实只是“关于正则表达式的POSIX规范”,它定义了BRE(Basic
Regular Expression,基本型正则表达式)和ERE(Extended Regular Express,扩展型正则表达
式)两大流派。在兼容POSIX的UNIX系统上,grep和egrep之类的工具都遵循POSIX规范,一些数据
库系统中的正则表达式也符合POSIX规范。
ANSI C与 Posix C
常见的正则表达式记法,其实都源于Perl,实际上,正则表达式从Perl衍生出一个显赫的流派,
叫做PCRE。
1. metacharacter(元字符/通配符)
. 任何单字符
* 任意0或多个字符
[aA] a或A, ^-否定,
[a-z]
^ 行开始
$ 行结尾
\{3\} 匹配3次
\{3,\} 至少匹配3次
\{3,6\} 匹配3-6次
\ 转义 \., \*, \\, \n
2. example:
[a-zA-Z][.?!]
[0-1][0-9][-/][0-3][0-9][-/][0-9][0-9] MM/DD/YY or MM-DD-YY
[^0-9]
[^aeiou]
\.DS "[^1]"
3. POSIX标准(Portable Operating System Interface for Computing Systems)
IEEE Std 1003.1 -2008
POSIX.1-2008
POSIX.1-2008 defines the Portable Operating System Interface (POSIX) requirements and
consists of the following
topics arranged as a series of volumes within the standard:
- Base Definitions
- System Interfaces
- Shell and Utilities
- Rationale (Informative)
4. 举例:
1>数据整理: 寻找"[["开头的一行数据, 结合excel进行数据处理:
$ cat trace.txt | xargs grep "^\[\["