php 正则表达式

web/asdfsadfas/asdfsdaf/badsfsadf/show_826.html
中间面包层数不定.
用正则怎么匹配呢
不想用explode
我想得到的最终的效果是
web/show_826.html
那要是web/和/show_826.html也不确定的话.能匹配得到这样web/show_826.html的结果吗?

<?php
$arr="web/asdfsadfas/asdfsdaf/badsfsadf/show_826.html
";
$arr=preg_replace("/(web\/)(.*)(show_826.html)/","\\1\\3",$arr);
echo $arr;
?>
运行结果:web/show_826.html
中间的东西都被替换掉了 就剩下了web/show_826.html了

试试这个
<?php

$arr="web/1/2/3/show_826.html
";
$arr=preg_replace("/^(.*\/)(.*?\/)(.*)$/U","\\1\\3",$arr);
echo $arr;
?>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-10-14
<?php
$a = 'web/asdfsadfas/asdfsdaf/badsfsadf/show_826.html';

$bool = preg_match_all('/[A-Za-z0-9\/]*\/(\w+\.html)$/', $a, $matches);

print_r($matches);
?>

<?php
$a = 'web/asdfsadfas/asdfsdaf/badsfsadf/show_826.html';

$bool = preg_match_all('/([^\/]+)[A-Za-z0-9\/]*\/(\w+\.html)$/', $a, $matches);

print_r($matches);
?>

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网