在字符串末尾匹配单词模式的正则表达式?

时间:2016-04-26 08:09:36

标签: php regex

什么是匹配字符串末尾的单词模式的正则表达式? 例如,以下内容应匹配“qwerty [numeric] [alpha]”:

"blah blah qwerty 8z"
"blahh blahh qwerty 4vx"

但不是:

"blah blah qwerty 8"
"blahh blahh qwerty 4"

2 个答案:

答案 0 :(得分:3)

$re = "/(\\w+\\s+\\d+\\w+)$/m"; 
$str = "blah blah qwerty 8z\nblahh blahh qwerty 4vx"; 

preg_match_all($re, $str, $matches);

DEMO

答案 1 :(得分:1)

$matches = null;
$returnValue = preg_match('/^.+(\d+[a-z]+)$/', 'blah blah qwerty 8z', $matches);
print_r($matches);
相关问题