【发布时间】:2015-08-18 01:22:21
【问题描述】:
我正在使用以下正则表达式模式来查找 url 的一部分:
$pattern = "(\d+)-.*";
//$pattern = "(\d+)-.*[.]htm.*";
$replacement = "/going/somewhere?$1";
$subject = "http://mudomain.com/59016-string.htm";
preg_match($pattern, $subject,$matches);
$final = preg_replace($pattern, $replacement, $subject);
echo $final;
var_dump($matches);
模式应该匹配
59016-string.htm
但我得到的只是 null 作为输出。 我在这里做错了什么?
已编辑: 得到解决方案后
供参考:
http://www.php.net/manual/en/regexp.reference.delimiters.php
【问题讨论】:
-
使用正则分隔符:
$pattern = '/(\d+)-.*/'; -
@stribizhev 该死的..我怎么错过了。你能写下你的评论作为答案吗?我会接受的。谢谢。