下面的代码是用来从字符串中获取季号的。但是它不能正常工作,因为季号在任何"Season"单词之前。
我试图将(\d+)\s*放在模式的前面,但是它没有返回任何内容。
如果是before or after the "Season" words?,我如何修正我的before or after the "Season" words?返回季节号?
$a = 'The Simpson 11 Season';
if ( preg_match( "/(Season|Stagione|S|T)\s*(\d+)/i", $a, $matches ) )
{
print_r( $matches );
}发布于 2018-03-18 16:33:59
以获得带有数字的子字符串
$a = 'I need the 11 Stagione';
if ( preg_match( "/\b(Season|Stagione|S|T)\s*\d+|\d+\s*(?1)\b/i", $a, $matches ) )
{
print_r( $matches[0] );
}见PHP演示。
详细信息
\b -一个单词边界(Season|Stagione|S|T) -第1组,任何替代子字符串\s* - 0+空格\d+ - 1+数字| -或\d+ - 1+数字\s* - 0+空格(?1) -第1组模式\b -一个单词边界https://stackoverflow.com/questions/49350266
复制相似问题