Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有字符串:
Detroit 10 New Jersey 2 (FINAL)
有没有办法在单个正则表达式中Detroit 10进行匹配?New Jersey 2
Detroit 10
New Jersey 2
如果城市名称的长度不同并且有些城市名称中有空格,我不知道该怎么做。
您可以使用正则表达式,使用数字来分隔城市名称的结尾。
喜欢:
/([^\d]*\d+)/
尝试这个:
$str = "Detroit 10 New Jersey 2 (FINAL)"; preg_match_all("/(\w+ )+\d+/", $str, $m); print_r( $m[0] );// the resulted strings are in this table $m[0]
希望能帮助到你