我不知道怎么表达清楚我的意思,举个例子
$content = "xxxhttp://xxx.com/hello.htmlxxx";
preg_match_all( "/http:\/\/xxx\.com\/[\w|']{4,17}\.html/iUs", $content, $result);
// 将会得到结果
array(
[0] => array(
[0] => http://xxx.com/hello.html
)
)我想同时得到表达式代表的 hello 该怎么做?
$content = "xxxhttp://xxx.com/hello.htmlxxx";
preg_match_all( "/http:\/\/xxx\.com\/[\w|']{4,17}\.html/iUs", $content, $result);
// 将会得到结果
array(
[0] => array(
[0] => http://xxx.com/hello.html
)
)我想同时得到表达式代表的 hello 该怎么做?
<?php
$content = "xxxhttp://xxx.com/hello.htmlxxx";
preg_match_all("/http:\/\/xxx\.com\/([\w|']{4,17})\.html/iUs", $content, $matches);
print_r($matches);
这也太送分了吧...这个不值这么多分的...
看看php手册中的pcre语法部分...
Array
(
[0] => Array
(
[0] => http://xxx.com/hello.html
) [1] => Array
(
[0] => hello
))通常的正则引擎子组编号都是这样确定的: 从左向右数左圆括号, 第几个左圆括号代表的子组, 就在结果数组中的哪个下标上, 下标从1开始. 此外, 通常都将0这个特殊的子组作为整个正则表达式的匹配结果
http://deerchao.net/tutorials/regex/regex.htm
这个是我查正则写法的参考文档http://cn.php.net/manual/zh/reference.pcre.pattern.syntax.php
这个是php使用的pcre正则的参考手册
如果 ([\w|']{4,17}) 话,那就要考虑到那些“'”该如何处理
虽然我不知道单引号为何会出现在 url 里