我试图找到一个匹配字符串的正则表达式模式,并返回该字符串之后的所有内容,直到'/'。我目前有:
'/forums\/topic\/\s*([^\/]*)/u'
但这会返回包括'forums / topic /'
在内的所有内容示例:string:
equest lorem ipsum dawhdk scripts. Problem: a href="__;_base_url_j;p_i;oj/index.php?/forums/topic/975-example-maps-to-local-rating/" then does something,
我只需要“975-example-maps-to-local-rating”
答案 0 :(得分:1)
$pat = '=forums/topic/\s*([^/]*)=u';
$str = 'equest lorem ipsum dawhdk scripts. Problem: a href="__;_base_url_j;p_i;oj/index.php?/forums/topic/975-example-maps-to-local-rating/" then does something,';
preg_match($pat, $str, $match);
var_dump($match);
输出:
array(2) {
[0]=>
string(45) "forums/topic/975-example-maps-to-local-rating"
[1]=>
string(32) "975-example-maps-to-local-rating"
}
答案 1 :(得分:1)