Metacharacters are characters with a special meaning:MetacharacterDescriptionTry it | Find a match for any one of the patterns separated by | as in: cat|dog|fish Try it » . Find any character Try it » ^ Finds a match as the beginning of a string as in: ^Hello Try it » ...
The following example will show you how to find and replace space with a hyphen character in a string using regular expression and PHPpreg_replace()function: Example Run this code» <?php$pattern="/\s/";$replacement="-";$text="Earth revolves around\nthe\tSun";// Replace spaces, newlin...
The preg_match_all() function matches all occurrences of pattern in string. 3preg_replace() The preg_replace() function operates just like ereg_replace(), except that regular expressions can be used in the pattern and replacement input parameters. ...
Someother string functions may need familiar with: intstrlen ( string $string ) stringstrtr ( string $str, string $from, string $to ) stringstrtr ( string $str, array $replace_pairs ) intstrcmp ( string $str1, string $str2 ) intstrcasecmp ( string $str1, string $str2 ) Note:PHP ...
Regular Expressions (PHP Cookbook)David SklarAdam TrachtenbergOreilly & Associates Inc
David LaneHugh E. Williams
PHP Regular Expressions Do a case-insensitive search for "w3schools" in a stringDo a case-insensitive count of the number of occurrences of "ain" in a stringReplace "Microsoft" with "W3Schools" in a string PHP Form Validation PHP Form Validation ...
(1)PCRE:(perl compatible regular expression)兼容perl的正则表达式。php推荐使用的 (2)POSIX:(portable operating system interface of unix)unix可移植操作系统接口。unix、linux系统等使用的正则 二、正则表达式的组成 如:/\d{6}/ 匹配一个六位的数字(可匹配邮政编码) ...
自PHP 5.3.0起,POSIX 正则表达式扩展被废弃。在 POSIX 正则和 PCRE 正则之间有一些不同,本页列出了在转向PCRE 时最显著的需要知道的不同点。 PCRE 函数需要模式以分隔符闭合。 不像POSIX,PCRE 扩展没有专门用于大小写不敏感匹配的函数。取而代之的是,支持使用i(PCRE_CASELESS)模式修饰符完成同样的工作。 其他...
endOfLinemark the expression with $endOfLine() thenadd a string to the expressionadd('foo') findalias for thenfind('foo') maybedefine a string that might appear once or notmaybe('.com') anythingaccept any stringanything() anythingButaccept any string but the specified charanythingBut(','...