apache httpd 和nginx的正则表达式

apache的httd服务器和nginx里,都广泛使用正则表达式,使用的正则表达式都为PCRE,

apache的说明 [url]http://httpd.apache.org/docs/current/rewrite/intro.html[/url]

nginx的说明 [url]http://nginx.org/en/docs/http/server_names.html[/url]

PCRE,为perl兼容的正则表达式库,全称PCRE(Perl Compatible Regular Expressions)
[url]http://baike.sogou.com/v56181697.htm[/url]


PCRE的说明文档 [url]http://perldoc.perl.org/perlre.html[/url]

表达式语法[url]http://blog.csdn.net/lgg201/article/details/6289751[/url]



//cygwin里的PCRE测试工具

$ man pcretest
DESCRIPTION

If pcretest is given two filename arguments, it reads from the first and writes to the second. If it is given only one filename argument, it reads from that file and writes to stdout. Otherwise, it reads from stdin and
writes to stdout, and prompts for each line of input, using "re>" to prompt for regular expressions, and "data>" to prompt for data lines.

When pcretest is built, a configuration option can specify that it should be linked with the libreadline library. When this is done, if the input is from a terminal, it is read using the readline() function. This provides
line-editing and history facilities. The output from the -help option states whether or not readline() will be used.

The program handles any number of sets of input on a single input file. Each set starts with a regular expression, and continues with any number of data lines to be matched against that pattern.

Each data line is matched separately and independently. If you want to do multi-line matches, you have to use the \n escape sequence (or \r or \r\n, etc., depending on the newline setting) in a single line of input to encode
the newline sequences. There is no limit on the length of data lines; the input buffer is automatically extended if it is too small.

An empty line signals the end of the data lines, at which point a new regular expression is read. The regular expressions are given enclosed in any non-alphanumeric delimiters other than backslash, for example:

/(a|bc)x+yz/

White space before the initial delimiter is ignored. A regular expression may be continued over several input lines, in which case the newline characters are included within it. It is possible to include the delimiter within
the pattern by escaping it, for example

/abc\/def/

If you do so, the escape and the delimiter form part of the pattern, but since delimiters are always non-alphanumeric, this does not affect its interpretation. If the terminating delimiter is immediately followed by a back‐
slash, for example,

/abc/\

then a backslash is added to the end of the pattern. This is done to provide a way of testing the error condition that arises if a pattern finishes with a backslash, because

/abc\/

is interpreted as the first line of a pattern that starts with "abc/", causing pcretest to read the next line as a continuation of the regular expression.




示例

$ pcretest
PCRE version 8.36 2014-09-26
re> /^(index\.php|images|js|robots|css|js\.txt|hm\.php)/
data> index.php
0: index.php
1: index.php
data> a/index.php
No match
data>
re> /\d+/
data> 100
0: 100
data> 1.0
0: 1
data> 12asd
0: 12
data>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值