正则表达式替换php中的链接
我不擅长正则表达式,我需要一些帮助 我有以下链接: 使用php时,正则表达式应该是什么,如下所示: 这就是我迄今为止所尝试的:正则表达式替换php中的链接,php,regex,expression,Php,Regex,Expression,我不擅长正则表达式,我需要一些帮助 我有以下链接: 使用php时,正则表达式应该是什么,如下所示: 这就是我迄今为止所尝试的: preg_match_all('/(\d+)(\w+)/', $str,$matches); 使用preg\u replace: $url = "http://www.mydomain.com/1/1/5/1/some-name-123-115194_7_9.jpg"; echo preg_replace('#(.+/).+-(.+)#','$1$2',$ur
preg_match_all('/(\d+)(\w+)/', $str,$matches);
使用
preg\u replace
:
$url = "http://www.mydomain.com/1/1/5/1/some-name-123-115194_7_9.jpg";
echo preg_replace('#(.+/).+-(.+)#','$1$2',$url)
>>> http://www.mydomain.com/1/1/5/1/115194_7_9.jpg
重新规划:
(.+/) # Match everything upto the last / and capture
.+- # Match upto the last -
(.+) # Match and capture everything else
# Replace with
$1$2 # The first and second capture groups
请看电视,你试过什么?在这里,我试过这个。preg_match_all(“/(\d+)(\w+/”,$str,$matches);我不会用正则表达式这样做。我将使用
parse_url()
函数将url分解为其组成部分,然后在末尾更改文件名,然后重新构建url。