【发布时间】:2020-10-15 19:27:33
【问题描述】:
我正在尝试为以下类型的字符串运行正则表达式:一个大写字母后跟一个数值。该字符串可以由多个这些字母-数字-值组合组成。这里有一些例子和我的预期输出:
A12B8Y9CC10
-> output [0 => 12, 1 => 8, 2 => 9] (10 is ignored, because there are two letters)
V5C8I17
-> output [0 => 5, 1 => 8, 2 => 17]
KK18II9
-> output [] (because KK and II are always two letters followed by numeric values)
I8VV22ZZ4S9U2
-> output [0 => 8, 1 => 9, 2 => 2] (VV and ZZ are ignored)
A18Z12I
-> output [0 => 18, 1 => 12] (I is ignored, because no numeric value follows)
我尝试使用 preg_match 通过以下正则表达式来达到此目的: /^([A-Z]{1}\d{1,)$/
但它没有给出预期的输出。你能帮我解决这个问题吗?
谢谢和最好的问候!
【问题讨论】:
标签: php regex numbers preg-match letter