PHP preg_replacejava正则表达式详解报错,应该怎么办?

preg_replace匹配的正则表达式 - PHP当前位置:& &&&preg_replace匹配的正则表达式preg_replace匹配的正则表达式&&网友分享于:&&浏览:7次求一个preg_replace匹配的正则表达式用PHP&,preg_replace函数匹配一个正则&
字符串为"house&and&market&and&"
替换掉最后一个and,要输出结果为"house&and&market&"
试了半天没写出来,谢谢各位大侠给个匹配的正则
------解决方案--------------------&?php&
$str&=&"house&and&market&and&";
$str&=&preg_replace('/and(\s*)$/',&'',&$str);
var_dump($str);
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有& 执行一个正则表达式搜索和替换
PHP preg_filter 执行一个正则表达式搜索和替换
preg_filter
preg_filter & 执行一个正则表达式搜索和替换
preg_filter
$replacement
[, int $limit = -1
[, int &$count
如果subject是一个数组, 返回一个数组,
其他情况返回一个字符串.
如果没有找到匹配或者发生了错误, 当subject是数组
时返回一个空数组, 其他情况返回NULL.
Example #1
比较preg_filter()
&?php$subject&=&array('1',&'a',&'2',&'b',&'3',&'A',&'B',&'4');&$pattern&=&array('/d/',&'/[a-z]/',&'/[1a]/');&$replace&=&array('A:$0',&'B:$0',&'C:$0');&echo&"preg_filter&returns
";print_r(preg_filter($pattern,&$replace,&$subject));&echo&"preg_replace&returns
";print_r(preg_replace($pattern,&$replace,&$subject));&?&
以上例程会输出:
preg_filter returns
[0] =& A:C:1
[1] =& B:C:a
[2] =& A:2
[3] =& B:b
[4] =& A:3
[7] =& A:4
preg_replace returns
[0] =& A:C:1
[1] =& B:C:a
[2] =& A:2
[3] =& B:b
[4] =& A:3
[7] =& A:4
PCRE Patterns
- 执行一个正则表达式的搜索和替换
- 执行一个正则表达式搜索并且使用一个回调进行替换
- 返回匹配模式的数组条目
- 返回最后一个PCRE正则执行产生的错误代码
PHP preg_filter note #1
As I had to work with PHP5.2.X and needed preg_filter I wrote a quick and dirty workaround.
& if (!function_exists('preg_filter')) {
&&& function preg_filter($pattern, $replace, $subject, $limit = -1 , &$count = null) {
&& && if(!is_array($subject)) {
&& & && $noArray = 1 ;
&& & && $subject = array($subject);
&& && $preg = preg_replace($pattern, $replace, $subject, $limit,& &$count);
&& && $diff = array_diff($preg, $subject);
&& && if($noArray == 1) $diff = implode($diff) ;
&& && return $diff ;
PHP preg_filter note #2
Another way to filter an array, and simply return the matching items: preg_grep!
PHP preg_filter note #3
If you want to just filter an array based on a regular expression, without replacing any of the array values, try RegexIterator:
PHPPCRE - 函数当前位置:&>&&>&php函数preg_replace 正则过滤掉div中所有内容preg_replace&--&执行正则表达式的搜索和替换mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit] )在subject中搜索pattern模式的匹配项并替换为replacement。如果指定了limit,则仅替换lpreg_replace&--&执行正则表达式的搜索和替换mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit] )在subject中搜索pattern模式的匹配项并替换为replacement。如果指定了limit,则仅替换limit个匹配,如果省略limit或者其值为 -1,则所有的匹配项都会被替换。例:$string&=&'hello&div&class&=&&div&&hello,div&/div&&p&class&=&&p&&hello,p&/p&';
$string&=&preg_replace('/&div(.*)&\/div&/is',&'',&$string);&&&//正则匹配,去掉文章中的DIV
echo&$输出:hello
hello,p可以看到,通过正则匹配,去掉了div并且div中的内容也一并去掉了,怎么过滤内容其实就看正则怎么写了。扩展:摘自网上的学习笔记&?php
$str=&as2223adfsf0s4df0sdfsdf&;
echo&preg_replace(&/0/&,&&,$str);//去掉0字符,此时相当于&replace的功能,&preg_replace(&/0/&,&A&,$str);&这样就是将0变成A的意思了
echo&preg_replace(&/[0-9]/&,&&,$str);//去掉所有数字
echo&preg_replace(&/[a-z]/&,&&,$str);&//这样是去掉所有小写字母
echo&preg_replace(&/[A-Z]/&,&&,$str);&//这样是去掉所有大写字母
echo&preg_replace(&/[a-z,A-Z]/&,&&,$str);&//这样是去掉所有字母
$str=&as2223adfsAAf0s4df0s中国人dD中南海DDfsdf&;
echo&preg_replace(&/[a-z,A-Z,0-9]/&,&&,$str);&//去掉所有字母和数字
经过以上的例子,相信大家知道,[&]&和里面的,有什么作用了。也可以看到,匹配的字符串必须加&/&/(看例子的第一个参数)
$str=&acsdcs&&sc&6666&sdcd&;
echo&preg_replace(&/&.*&/&,&&,$str);
//这个是表示去除以&开头,以&结尾的那部份,输出结果是:acsdcssdcd
注意:上面的&.*&是表示任何字符,也就是说不管&&包住的是什么都去掉其中.&表示任意字符,&*&表示任意个数
现在我们来改动一下,如果不想是任何个数呢?
$str=&acsdcs&&sc&6666&sdcd&;
echo&preg_replace(&/&.{4}&/&,&&,$str);&//此时输出:acsdcs&&scsdcd因为{4}指定了条件:&&内为4个字符的才满足条件,所以&&不符合条件,没有被替换。
注意:这时我们又学到了一个知识点{数字}&表示指定前面的个数,*就表示是任意个(0--无限个)
表示重复次数的除了&*,&{指定次数}&表示,还有很多表达形式:
$str=&acsdcs&&sc&6666&sd&&cd&;
echo&preg_replace(&/&[0-9]*&/&,&&,$str);
//输出acsdcscd
echo&&&hr&&;
echo&preg_replace(&/&[0-9]+&/&,&&,$str);
//输入acsdcsscsd&&cd
上面的例子只要是为了&表达&*&与+的区别&,*&表示重复0数或n&次,而+&表示1次以上,即一例中&[0-9]+&&表示&&里面至少要有一个数字才符合条件。
相信这时大家知道,为什么上例中用*&和用+输出的结果不同了吧
$str=&acsdcs&&sc&6666&sd&&cd&;
echo&preg_replace(&/&[0-9]?&/&,&&,$str);
//输出acsdcs&&sc&6666&sdcd
看[0-9]?&这里的?表示要是0次或1&次,超过1次又不符合条件了。
总结一下,上面我们学会了&*&+&?&和大括号{}表示重复次数的方法。
----------------------------------------------------------------------------------------------------
&&&&$s=preg_replace(&/(.*?[月票|求|更].*?)/i&,&&,$s);
&&&&preg_match_all('/href=\&([0-9]+)\.shtm&&(.+?)&\/a&/i',$s,$arr_dstorycate);&&&&
&&&&print_r($arr_dstorycate);
----------------------------------------------------------------------------------------------------
&&&preg_match_all(&/&img.*?src=[\\\'|&\\\&](.*?(?:[\.gif|\.jpg]))[\\\'|\\\&].*?[\/]?&/i&,$content,$arr_dstorycate);&&&&&&&&&&&&
&&&print_r($arr_dstorycate);------分隔线----------------------------上一篇:下一篇:评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)热点推荐大多数据情况下我们对于session过期时间使用的是默认设置的时间,而对于一些有特殊要求的情况下我们可以设置一下session过期时间。对此,可以在PHP中,设置php.ini,找到session.gc_maxlifetime = 1440 #(PH...stringnumber_format(float$number[,int$decimals]) string number_format (float$number,int$decimals,string$dec_point,string$thousands_sep) decimals:小数点后面2位 dec_point:小数点用什么符号 thousands_sep:每隔3位时用什么符号 eg: ?php...
以前在去掉数组的空值是都是强写foreach或者while的,利用这两个语法结构来删除数组中的空元素,简单代码如下:PHP代码$v){
i...PHP max() max() 函数:返回参数中数值最大的值,可以比较无限多个值。 语法: mixed max( number arg1, number arg2 ... ) mixed max( array numbers [, array ...] ) 例子: ?phpecho max(1, 3, 5); // 输出:5echo max(array(2, 4, 5))...热点内容& 执行一个正则表达式搜索并且使用一个回调进行替换
PHP preg_replace_callback 执行一个正则表达式搜索并且使用一个回调进行替换
preg_replace_callback
preg_replace_callback & 执行一个正则表达式搜索并且使用一个回调进行替换
preg_replace_callback
[, int $limit = -1
[, int &$count
要搜索的模式, 可以使字符串或一个字符串数组.
一个回调函数, 在每次需要替换时调用, 调用时函数得到的参数是从subject
中匹配到的结果. 回调函数返回真正参与替换的字符串.
你可能经常会需要callback函数而
仅用于preg_replace_callback()一个地方的调用. 在这种情况下, 你可以
使用来定义一个匿名函数作
为preg_replace_callback()调用时的回调. 这样做你可以保留所有
调用信息在同一个位置并且不会因为一个不在任何其他地方使用的回调函数名称而污染函数名称空间.
Example #1 preg_replace_callback()和
&?php/*&一个unix样式的命令行过滤器,&用于将段落开始部分的大写字母转换为小写.&*/$fp&=&fopen("php://stdin",&"r")&or&die("can't&read&stdin");while&(!feof($fp))&{&&&&$line&=&fgets($fp);&&&&$line&=&preg_replace_callback(&&&&&&&&'|&p&s*w|',&&&&&&&&create_function(&&&&&&&&&&&&//&single&quotes&are&essential&here,&&&&&&&&&&&&//&or&alternative&escape&all&$&as&$&&&&&&&&&&&&'$matches',&&&&&&&&&&&&'return&strtolower($matches[0]);'&&&&&&&&),&&&&&&&&$line&&&&);&&&&echo&$line;}fclose($fp);?&
要搜索替换的目标字符串或字符串数组.
对于每个模式用于每个subject字符串的最大可替换次数.
默认是-1(无限制).
如果指定, 这个变量将被填充为替换执行的次数.
如果subject是一个数组,
preg_replace_callback()返回一个数组, 其他情况返回字符串.
错误发生时返回NULL.
如果查找到了匹配, 返回替换后的 目标字符串(或字符串数组), 其他情况subject
将会无变化返回.
Example #2 preg_replace_callback()示例
&?php//&将文本中的年份增加一年.$text&=&"April&fools&day&is&04/01/2002
";$text.=&"Last&christmas&was&12/24/2001
";//&回调函数function&next_year($matches){&&//&通常:&$matches[0]是完成的匹配&&//&$matches[1]是第一个捕获子组的匹配&&//&以此类推&&return&$matches[1].($matches[2]+1);}echo&preg_replace_callback(&&&&&&&&&&&&"|(d{2}/d{2}/)(d{4})|",&&&&&&&&&&&&"next_year",&&&&&&&&&&&&$text);?&
以上例程会输出:
April fools day is 04/01/2003
Last christmas was 12/24/2002
Example #3 preg_replace_callback()使用递归构造处理BB码的封装
&?php$input&=&"plain&[indent]&deep&[indent]&deeper&[/indent]&deep&[/indent]&plain";function&parseTagsRecursive($input){&&&&/*&译注:&对此正则表达式分段分析&&&&&*&首尾两个#是正则分隔符&&&&&*&[indent]&匹配一个原文的[indent]&&&&&*&((?:[^[]|[(?!/?indent])|(?R))+)分析:&&&&&*&&&&&&&&&(?:[^[]|[(?!/?indent])分析:&&&&&*&&&&&&&&&&&&&首先它是一个非捕获子组&&&&&*&&&&&&&&&&&&&两个可选路径,&一个是非[字符,&另一个是[字符但后面紧跟着不是/indent或indent.&&&&&*&&&&&&&&&(?R)&正则表达式递归&&&&&*&&&&&[/indent]&匹配结束的[/indent]&&&&&*&/&&&&$regex&=&'#[indent]((?:[^[]|[(?!/?indent])|(?R))+)[/indent]#';&&&&if&(is_array($input))&{&&&&&&&&$input&=&'&div&style="margin-left:&10px"&'.$input[1].'&/div&';&&&&}&&&&return&preg_replace_callback($regex,&'parseTagsRecursive',&$input);}$output&=&parseTagsRecursive($input);echo&$?&
- 执行一个正则表达式的搜索和替换
- 返回最后一个PCRE正则执行产生的错误代码
- Create an anonymous (lambda-style) function
类型的信息
PHP preg_replace_callback note #1
also note that when you are using this functionality in a class and you need variables in that class, you can use a non static function as callback. array($this, functionName) should be enough to call an function of the class.
Either use create_function if you require the code only once,
use a static class function if no need for accessing variables in that class. or use the array metioned earlier in my post for having access to class variables or other functions!
PHP preg_replace_callback note #2
I noticed that 'e' modifier use addslashed on result
function wyczysc_strongi($string) {
&&& if(mb_strlen($string,'UTF-8')&60) {
&& & && return $
&&& } else {
&& & && return '&strong&'.$string.'&/strong&';
$tresc = "&strong&fajna dupa's&/strong&";
$tresc = preg_replace("/&strong&(.*?)&/strong&/ie",'wyczysc_strongi("$1")',$tresc);
echo $tresc will give: &strong&fajna dupa's&/strong&
solution: $tresc = stripslashes($tresc);
after callback
PHP preg_replace_callback note #3
I needed a simple code to tidy up a string. It simply had to upper-case letters after dot. Simple code to do so:
$string = preg_replace_callback(
'|(?:.)(?:s*)(w{1})|Ui',
create_function('$matches', 'return ". ".strtoupper($matches[1]);'), ucfirst($string)
$string = 'lorem ipsum dolor sit amet, consectetur adipiscing elit. sed ullamcorper diam eu lorem varius nec porta elit iaculis.';
echo preg_replace_callback(
'|(?:.)(?:s*)(w{1})|Ui',
create_function('$matches', 'return ". ".strtoupper($matches[1]);'), ucfirst($string)
Will output: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ullamcorper diam eu lorem varius nec porta elit iaculis.
$string = 'lorem ipsum dolor sit amet, consectetur adipiscing elit.& & & & & & & && sed ullamcorper diam eu lorem varius nec porta elit iaculis.';
echo preg_replace_callback(
'|(?:.)(?:s*)(w{1})|Ui',
create_function('$matches', 'return ". ".strtoupper($matches[1]);'), ucfirst($string)
Will output: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ullamcorper diam eu lorem varius nec porta elit iaculis.
Nothing fancy, but useful :)
PHP preg_replace_callback note #4
The pcre.backtrack_limit option (added in PHP 5.2) can trigger a NULL return, with no errors. The default pcre.backtrack_limit value is 100000. If you have a match that exceeds about half this limit it triggers a NULL response.
e.g. My limit was at 100000 but 500500 triggered a NULL response. I'm not running unicode but I *guess* PCRE runs in utf-16.
PHP preg_replace_callback note #5
Created this to fetch the link and name of an anchor tag. I use this when cleaning an HTML email to text. Using regex for HTML is not recommended but for this purpose I see no issue with it. This is not designed to work for nested anchors.
A note to keep in mind:
I was primarily concerned with valid HTML so if attributes do no use ' or " to contain the values then this will need to be tweaked.
If you can edit this to work better, please let me know.
function replaceAnchorsWithText($data) {
&&& $regex& = '/(&as*'; $regex .= '(.*?)s*'; $regex .= 'href=['"]+?s*(?P&link&S+)s*['"]+?'; $regex .= 's*(.*?)s*&s*'; $regex .= '(?P&name&S+)'; $regex .= 's*&/a&)/i'; if (is_array($data)) {
&& & && $data = "{$data['name']}({$data['link']})";
&&& return preg_replace_callback($regex, 'replaceAnchorsWithText', $data);
$input& = 'Test 1: &a href="http: //php.net1"&PHP.NET1&/a&.&br /&';
$input .= 'Test 2: &A name="test" HREF='HTTP: //PHP.NET2' target="_blank"&PHP.NET2&/A&.&BR /&';
$input .= 'Test 3: &a hRef=http: //php.net3&php.net3&/a&&br /&';
$input .= 'This last line had nothing to do with any of this';
echo replaceAnchorsWithText($input).'&hr/&';
Will output:
Test 1: PHP.NET1(http: //php.net1).
Test 2: PHP.NET2(HTTP: //PHP.NET2).
Test 3: php.net3 (is still an anchor)
This last line had nothing to do with any of this
PHP preg_replace_callback note #6
The good version of the class PhpHex2Str
class PhpHex2Str
&&& private $strings;
&&& private static function x_hex2str($hex) {
&& & && $hex = substr($hex[0], 1);
&& & && $str = '';
&& & && for($i=0;$i & strlen($hex);$i+=2) {
&& & & & && $str.=chr(hexdec(substr($hex,$i,2)));
&& & && return $str;
&&& public function decode($strings = null) {
&& & && $this-&strings = (string) $strings;
&& & && return preg_replace_callback('#\%[a-zA-Z0-9]{2}#', 'PhpHex2Str::x_hex2str', $this-&strings);
$obj = new PhpHex2Str;
$strings = $obj-&decode($strings);
var_dump($strings);
PHP preg_replace_callback note #7
Decode Hexa to Strings =)
class PhpHex2Str
&&& private $strings;
&&& private function x_hex2str($hex) {
&& & && $hex = substr($hex[0], 1);
&& & && $str = '';
&& & && for($i=0;$i & strlen($hex);$i+=2) {
&& & & & && $str.=chr(hexdec(substr($hex,$i,2)));
&& & && return $str;
&&& public function decode($strings = null) {
&& & && $this-&strings = (string) $strings;
&& & && return preg_replace_callback('#\%[a-zA-Z0-9]{2}#', 'x_hex2str', $this-&strings);
$strings = 'a %20 b%0A h %27 h %23';
$obj = new PhpHex2Str;
$strings = $obj-&decode($strings);
var_dump($strings);
PHP preg_replace_callback note #8
If you're looking to show only the first digit and last four digits of a credit card number (4xxxxxxxxxxxx2331) use something like this:
preg_replace_callback('/((.)(.*))?(.{4})/', create_function('$x', 'return $x[2].str_repeat("x", strlen($x[3])).$x[4];'), '$CCNUMBER')
PHP preg_replace_callback note #9
When you use preg_replace_callback in a class and have the callback function as a private method of that class, you need to set the callback function name like className::CallBack.
self::CallBack does not work and returns an error:
"Cannot call method self::CallBack() or method does not exist"!
class myClass{
&&& public function parsetext($text){
&& & && return preg_replace_callback('|([a-c])|i', 'myClass::preg_tolower', $text);
&&& public function parsefail($text){
&& & && return preg_replace_callback('|([a-c])|i', 'self::preg_tolower', $text);
&&& private static function preg_tolower($matches){
&& & && return strtolower($matches[1]);
$parser = new myClass;
echo $parser-&parsetext('ABCDEFGH');
echo $parser-&parsefail('ABCDEFGH');
PHP preg_replace_callback note #10
A simple function to replace a list of complete words or terms in a string (for PHP 5.3 or above because of the closure):
function replace_words($list, $line, $callback) {
&&& return preg_replace_callback(
&& & && '/(^|[^\w\-])(' . implode('|', array_map('preg_quote', $list)) . ')($|[^\w\-])/mi',
&& & && function($v) use ($callback) { return $v[1] . $callback($v[2]) . $v[3]; },
&& & && $line
Example of usage:
$list = array('php', 'apache web server');
$str = "php and the apache web server work fine together. php-gtk, for example, won't match. apache web servers shouldn't too.";
echo replace_words($list, $str, function($v) {
&&& return "&strong&{$v}&/strong&";
PHP preg_replace_callback note #11
This function does not support named subpatterns, so you can't do
preg_replace_callback('/(?&char&[a-z])/', 'callback', 'word');
function callback($matches) {
&&& var_dump($matches);
and expect to get $matches['char'] in your function.
PHP preg_replace_callback note #12
If you're planning to use preg_replace_callback inside a class, you need to use the array() function:
class MyClass
& function preg_callback_url($matches)
&&& $url = $matches[1].$matches[2];
&&& $text = '';
&&& $pos = strpos($url,' ');
&&& if ($pos!==FALSE) {
&& && $text = trim(substr($url,$pos+1));
&& && $url = substr($url,0,$pos);
&&& return '&a href="'.$url.'" rel="nofollow"&'.(($text!='') ? $text : $url).'&/a&';
& function ParseText($text)
&&& return preg_replace_callback('/[(http|https|ftp)(.*?)]/iS',array( &$this, 'preg_callback_url'), $text);
PHP preg_replace_callback note #13
This is what i use to read log files and do dns lookups on the ip's from the file.
function resolve_logs($arr) {
&& & && return gethostbyaddr($arr[0]);
$logent=file('yourlogfile');
$ipaddr = '/d{1,3}.d{1,3}.d{1,3}.d{1,3}/';
$logent = preg_replace_callback($ipaddr, resolve_logs, $logent);
PHP preg_replace_callback note #14
When you access variables from outside in a callback function, use the $global keyword:
global $x;
$str = '&Bla bla. &#x25';
$find = '/(&)([^#])/';
$replace = create_function('$f',
&&& 'global $x; $x ++; return $f[2];';
$str2 = preg_replace_callback($find, $replace, $str);
PHP preg_replace_callback note #15
To access a local variable within a callback, use currying (delayed argument binding). For example
function curry($func, $arity) {
&&& return create_function('', "
&& & && $args = func_get_args();
&& & && if(count($args) &= $arity)
&& & & & && return call_user_func_array('$func', $args);
&& & && $args = var_export($args, 1);
&& & && return create_function('','
&& & & & && $a = func_get_args();
&& & & & && $z = ' . $args . ';
&& & & & && $a = array_merge($z,$a);
&& & & & && return call_user_func_array('$func', $a);
&& & && ');
function on_match($transformation, $matches)
&&& return $transformation[strtolower($matches[1])];
$transform = array('a' =& 'Well,', 'd'=&'whatever', 'b'=&' ');
$callback = curry(on_match, 2);
echo preg_replace_callback('/([a-z])/i', $callback($transform), 'Abcd');
"Well, whatever"
The magic lies in this curry function I found here:
PHP preg_replace_callback note #16
To access a local variable within a callback, use currying (delayed argument binding). For example
function curry($func, $arity) {
&&& return create_function('', "
&& & && $args = func_get_args();
&& & && if(count($args) &= $arity)
&& & & & && return call_user_func_array('$func', $args);
&& & && $args = var_export($args, 1);
&& & && return create_function('','
&& & & & && $a = func_get_args();
&& & & & && $z = ' . $args . ';
&& & & & && $a = array_merge($z,$a);
&& & & & && return call_user_func_array('$func', $a);
&& & && ');
function on_match($transformation, $matches)
&&& return $transformation[strtolower($matches[1])];
$transform = array('a' =& 'Well,', 'd'=&'whatever', 'b'=&' ');
$callback = curry(on_match, 2);
echo preg_replace_callback('/([a-z])/i', $callback($transform), 'Abcd');
"Well, whatever"
The magic lies in this curry function I found here:
PHP preg_replace_callback note #17
To spend more than one parameter can do the following (note the "e" parameter in preg_replace function)
$array = array(
3=&'Three'
function search(&$array, $str, $foo, $bar){
&&& return ( empty($array[$str]) ? '['.$foo.'-'.$bar.']' : $array[$str] );
function keys(&$array, $str,$foo,$bar){
&&& return preg_replace('/[(.*?)]/e',"search($array,$1,$foo,$bar)",$str);
$str = "One [1] Two [2] Three [3], Other parameter [22]";
echo keys($array, $str,'Foo','Bar');
PHP preg_replace_callback note #18
The first example is bad, because it creates function for every line it processes. When the file has many lines, you could easily run out of memory. The code should be changed so, that create_function() is used outside of loop.
PHP preg_replace_callback note #19
preg_replace_callback returns NULL when pcre.backtrack_ this sometimes occurs faster then you might expect. No er so don't forget to check for NULL yourself
PHP preg_replace_callback note #20
it is much better on preformance and better practice to use the preg_replace_callback function instead of preg_replace with the e modifier.
function a($text){return($text);}
// 2.76 seconds to run 50000 times
preg_replace("/{(.*?)}/e","a('\1','\2','\3',$b)",$a);
// 0.97 seconds to run 50000 times
preg_replace_callback("/{(.*?)}/s","a",$a);
PHPPCRE - 函数}

我要回帖

更多关于 java正则表达式详解 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信