PCRE
在线手册:中文 英文
PHP手册

简介

这些函数中使用的模式语法非常类似perl. 表达式必须用分隔符闭合, 比如一个正斜杠(/). 分隔符可以使任意非字母数字, 除反斜杠(\)和空字节之外的非空白ascii字符. 如果分隔符 在表达式中使用, 需要使用反斜线进行转义. 自php 4.0.4开始, 可以使用perl样式的(), {}, []以及<>作为分隔符. 更详细的解释参见模式语法.

结束分隔符后面可以紧跟模式修饰符来影响匹配效果. 参见模式修饰符.

PHP也支持使用POSIX扩展正则表达式函数 的POSIX扩展语法的正则表达式

Note:

这个扩展维护了一个已编译正则表达式的全局线程化缓存(最大4096).

Warning

你应该知道一些PCRE的限制. 阅读» http://www.pcre.org/pcre.txt 获取更详细信息.

PCRE库是一个实现了与perl 5在语法和语义上略有差异(详见下文)的正则表达式模式匹配功能的函数集. 当前的实现对应于perl 5.005.


PCRE
在线手册:中文 英文
PHP手册
PHP手册 - N: 简介

用户评论:

m dot colombo at NOSPAM dot esi dot it (12-Oct-2009 11:22)

Converting POSIX regex patters to PCRE is non-trivial. I had many (about 17.000) patterns stored in a DB, and found that surrounding one with delimiters (such as '/'), after quoting them, is not enough.

I've been biten by a \r that slipped into a pattern (that was supposed to be \.r and became .\r instead). Too bad in PCRE it stands for carriage-return.

AFAIK, there's no way to disable this behaviour and make PCRE more POSIX compatibile. You have to look for every single escape sequence that has no meaning in POSIX regex but has one in PCRE and remove the backslash.

Before POSIX regex are removed it would be really cool to have a function that converts a POSIX regex pattern into the equivalent PCRE one.