使用php preg_match使用正则表达式提取数字和符号字符串

使用php preg_match使用正则表达式提取数字和符号字符串,php,preg-match,Php,Preg Match,如果我想像这样从URL中提取“-i123213131345”,我必须使用什么正则表达式http://example.com/blabla-bla-i123213131345/blabla尝试-i[0-9]+模式 样本: $str = 'http://example.com/blabla-bla-i123213131345/blabla'; $pattern = '/-i[0-9]+/'; preg_match($pattern, $str, $matches); var_dump($matche

如果我想像这样从URL中提取“-i123213131345”,我必须使用什么正则表达式
http://example.com/blabla-bla-i123213131345/blabla

尝试
-i[0-9]+
模式

样本:

$str = 'http://example.com/blabla-bla-i123213131345/blabla';
$pattern = '/-i[0-9]+/';
preg_match($pattern, $str, $matches);
var_dump($matches);


在实现正则表达式之前使用它们的有用工具。学习
Regex也很有帮助

我曾经尝试过类似“/(-I[0-9])/”的东西,但是没有成功,为什么会成功呢?里面没有下划线
/-i\d+/
模式中也没有任何量词,非常感谢这个/-i\d+/。它非常适合meSo,对于一个新用户来说,这需要付出很多努力。它非常适合你me@Jari这个问题的形式不好,但这是新用户的错误