$strs="asdfgoejgoasjpodgajdlkgljgsldfgdsfghvcxsdfsdf";
$num = preg_replace("#[^([a-f][g-i])]#U"," ",$strs);
echo $num;
请教各位,这个正则表达式为什么不对?总是出错“Compilation failed: unmatched parentheses at offset 13”为什么不能把[a-f][g-i]括起来,作为一个因子?
$num = preg_replace("#[^([a-f][g-i])]#U"," ",$strs);
echo $num;
请教各位,这个正则表达式为什么不对?总是出错“Compilation failed: unmatched parentheses at offset 13”为什么不能把[a-f][g-i]括起来,作为一个因子?
$num = preg_replace("#[^([a-f][g-i])]#U"," ",$strs);
echo $num; 是这样的:本来$num = preg_replace("#[a-f][g-i]#U"," ",$strs); 替换的结果是:
“asd oejgoasjpo ajdlkgljgsld ds hvcxsdfsdf“,而我想得到相反的结果。请教这样的正则表达式应该怎么写?
$num = preg_replace("#[([a-f][g-i])]#U"," ",$strs);
echo $num;
运行不了。
<?php
$strs="asdfgoejgoasjpodgajdlkgljgsldfgdsfghvcxsdfsdf";
$num = preg_replace("#[a-f][g-i]#U"," ",$strs);
print_r($num);
echo("\n");
preg_match_all("#[a-f][g-i]#U",$strs,$num);
print_r(implode(' ',$num[0]));?>
$strs="asdfgoejgoasjpodgajdlkgljgsldfgdsfghvcxsdfsdf";
$num = preg_replace("/[aosvx]|[c-h][j-l]/"," ",$strs);
echo $num;
?>
其实我是想得到这么一个结果:$str="地方sdad发sd的 ⑷ ⑸ ⑹ ⑺ ⑻ ⑼ ⑽ ⑾ ⑿ ⒀ ⒁ ";这个字符串中,中文,字母以及特殊的字符都有,我想通过正则表达式,把中文挑出来:
“地方 发 的”,您提供的思路可以得到“地 方 发 的”,但把“地方”两个字分开了,我就没法得到原始字符串中的词语,请大哥不吝赐教。谢谢。
我用的正则表达式是:#[\xB0-\xF7][\xA1-\xFE]#这个表达式是将中文挑出来,而我想得到的结果是把非中文用空格代替。