`

apache httpd 和nginx的正则表达式

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

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

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

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


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

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


//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>




分享到:
评论

相关推荐

    浅谈apache和nginx的rewrite的区别

    6. URL变量的引用:Nginx中经常用`$1`、`$2`等来引用捕获的正则表达式中的子匹配内容,而在Apache中则是`$1`、`$2`加上百分号`%`,如`%1`、`%2`。 在迁移时,从Apache迁移到Nginx,或者从Nginx迁移到Apache的...

    Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解

    - 在Web1和Web2服务器上安装Apache HTTP Server (httpd)。 **2. 提供测试页面** - 在每个Web服务器上创建一个测试页面。 **3. 启动httpd服务** - 启动httpd服务以确保测试页面可用。 **4. 测试一下** - 访问测试...

    运维所需的10个技能.zip

    WEB服务器 nginx tomcat apache httpd 会写shell脚本bash,perl,python 正则表达式sed awk grep 数据库 防火墙 自动化运维工具zabbix,cacti,nagios 服务器集群 数据库热备份 数据热备RAID 数据备份工具rsync,inotify ...

    Apache权威指南第三版

    掌握正则表达式和RewriteRule的应用,能够帮助你更好地处理网站的URL结构。 四、安全与性能优化 书中会讲解如何配置Apache以提高安全性,包括使用SSL/TLS加密通信、设置防火墙规则、限制非法访问等。同时,也会讨论...

    BASH-log_nginx:httpd 日志的简单解析器(nginxapache)

    2. **解析日志格式**:nginx 和 apache 的日志格式有所不同,脚本可能包含针对这两种格式的解析逻辑,如使用正则表达式分割每条记录。 3. **统计信息**:脚本可能计算访问次数、IP 地址频率、错误率等统计信息。 4. ...

    Nginx和Apache几种防盗链配置方法实例

    这个配置例子中,`~*`是一个正则表达式,用于匹配以`.gif`, `.jpg`, `.png`, `.swf`, `.flv`, 或 `.bmp`结尾的文件。`valid_referers`定义了合法的来源,`none`代表直接输入URL访问,`blocked`代表被防火墙阻止的...

    linux的php7.4.25编译安装文件

    6. **PCRE (Perl Compatible Regular Expressions)**:用于正则表达式的库。 7. **Libxml2**:处理XML和HTML文档的库。 8. **Oniguruma**:正则表达式库,为PHP提供更强大的匹配能力。 9. **GMP (GNU Multiple ...

    【24】基于Centos7.5源码编译LAMP架构.docx

    - pcre (Perl Compatible Regular Expressions):用于支持Apache中的正则表达式功能。 2. **编译安装Apache**:下载httpd-2.4.37.tar.gz,按照官方文档进行编译安装。 3. **安装MySQL/MariaDB**:下载mysql-...

    精仿360问答伪静态

    以上介绍了四种不同Web服务器环境下实现伪静态配置的方法,包括Apache的`httpd.ini`和`httpd.conf`、`.htaccess`,Nginx的`Nginx.txt`以及IIS的`web.config`。每种方法都有其特点,但核心思想都是通过URL重写技术来...

    php url路由入门实例

    例如,`^view-([0-9]+)\.html$`是一个正则表达式,匹配以`view-`开头,后跟一个或多个数字的字符串,并将匹配的数字捕获为 `$1`。 - `RewriteRule`配置参数: - `R`:强制外部重定向,使浏览器显示新的URL。 - `F...

    PHP7安装Redis扩展教程【Linux与Windows平台】

    在本文中,我们将深入探讨如何在PHP7环境下安装Redis扩展,包括在Linux和Windows操作系统上的步骤。...对于初学者来说,可以参考更多的PHP扩展开发教程、面向对象编程教程以及正则表达式等资源,以提升自己的技能。

Global site tag (gtag.js) - Google Analytics