Regular Expressions Tutorial on russian language is accessible on http://www.pcre.ru
CXXII. Perl 兼容正则表达式函数简介本类函数中所使用的模式极其类似 Perl。表达式应被包含在定界符中,如斜线(/)。任何不是字母、数字或反斜线(\)的字符都可以作为定界符。如果作为定界符的字符必须被用在表达式本身中,则需要用反斜线转义。自 PHP 4.0.4 起,也可以使用 Perl 风格的 (),{},[] 和 <> 匹配定界符。详细解释见模式语法。 结束定界符的后面可以跟上不同的修正符以影响匹配方式。见模式修正符。 PHP 也支持 POSIX 扩展语法的正则表达式,见 POSIX 扩展正则表达式函数。
需求正则表达式的支持是由 PCRE(Perl Compatible Regular Expression)库提供的,这是个开放源代码的软件,作者为 Philip Hazel,版权属于英国剑桥大学。可于以下地址获得:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/。 安装自 PHP 4.2.0 起这些函数默认被激活。可以通过 --without-pcre-regex 禁用 PCRE 函数。如果不使用绑定的库的话,用 --with-pcre-regex=DIR 来指定 PCRE 库文件和头文件的路径。对早期版本必须在编译时用 --with-pcre-regex[=DIR] 才能使用这些函数。 PHP 的 Windows 版本已经内置该扩展模块的支持。无需加载任何附加扩展库即可使用这些函数。 运行时配置本扩展模块在 php.ini 中未定义任何配置选项。 资源类型本扩展模块未定义任何资源类型。 预定义常量以下常量由本扩展模块定义,因此只有在本扩展模块被编译到 PHP 中,或者在运行时被动态加载后才有效。 表格 1. PREG 常量
add a note
User Contributed Notes
nickspring at mail dot ru
14-Oct-2006 10:47
Regular Expressions Tutorial on russian language is accessible on http://www.pcre.ru
toomuchphp-phpman at yahoo dot com
03-Aug-2006 06:33
RE: filippo dot toso at humanprofile dot biz
filippo dot toso at humanprofile dot biz
03-Aug-2006 06:11
Here it is a simple PHP function that escapes a string to safely use it in a Regular Expression, very useful to include unknown strings in PCRE patterns:
lgandras at hotmail dot com
20-Feb-2006 06:19
I read this part, but i couldn't undertand a single word beacause before i must know Basic regular expression. Somebody put a link for PERL that is almost like PHP but here is one totally dedicated to PHP:
Gokul
06-Feb-2006 04:59
I came accross this nice tutorial for regural expression in perl
alexbodn at 012 dot n@t dot il
09-Jan-2006 10:45
here is an annotation to my note from 28-Apr-2005 03:52, due to the welcome contribution of dipesh khakhkhar:
richardh at phpguru dot org
23-Sep-2005 02:50
There's a printable PDF PCRE cheat sheet available here:
hfuecks at nospam dot org
04-Jul-2005 05:21
Good PCRE tutorial at http://www.tote-taste.de/X-Project/regex/ - well explained but still in depth
alexbodn at 012 dot n@t dot il
28-Apr-2005 09:52
Here is a small function to determine whether a string is a [valid] preg expression.
Ned Baldessin
24-Oct-2004 09:08
If you want to perform regular expressions on Unicode strings, the PCRE functions will NOT be of any help. You need to use the Multibyte extension : mb_ereg(), mb_eregi(), pb_ereg_replace() and so on. When doing so, be carefull to set the default text encoding to the same encoding used by the text you are searching and replacing in. You can do that with the mb_regex_encoding() function. You will probably also want to set the default encoding for the other mb_* string functions with mb_internal_encoding().
steve at stevedix dot de
20-Jul-2004 08:17
Something to bear in mind is that regex is actually a declarative programming language like prolog : your regex is a set of rules which the regex interpreter tries to match against a string. During this matching, the interpreter will assume certain things, and continue assuming them until it comes up against a failure to match, which then causes it to backtrack. Regex assumes "greedy matching" unless explicitly told not to, which can cause a lot of backtracking. A general rule of thumb is that the more backtracking, the slower the matching process.
Biju
21-Sep-2003 12:00
Regular Expressions Tutorial from non PHP sites
hrz at geodata dot soton dot ac dot uk
07-Mar-2002 03:33
If you're venturing into new regular expression territory with a lack of useful examples then it would pay to get familiar with this page: | ||||||||||||||||||