Home > Article > Backend Development > 正则表达式
[img]XXXXXXg;base64,iVQA/XXXXXXXXXXXXXXX[/img]
$s = '[img]XXXXXXg;base64,iVQA/XXXXXXXXXXXXXXX[/img]';echo preg_replace('/(?<=])[^[]+/', '', $s);[img][/img]
$s = '[img]XXXXXXg;base64,iVQA/XXXXXXXXXXXXXXX[/img]';echo preg_replace('/(?<=])[^[]+/', '', $s);[img][/img]
$s = '[a]XXXXXXg;base64,iVQA/XXXXXXXXXXXXXXX[/a]';echo preg_replace('/(?<=])[^[]+/', '', $s);[a][/a]
echo preg_replace('/(?<=\[img\])[^[]+/', '', $s);
$str = '[img]XXXXX[/img]';$regx = '/\[img\](.*)\[\/img\]/';$rep_result = preg_replace_callback( $regx, function($match){ return str_replace($match[1],'',$match[0]); }, $str);