正则表达式检测字符串开头的数字。

时间:2010-12-30 18:52:45

标签: php regex

我有一个字符串,包括: 一些数字, 一封信, 一些数字和字母。

例如:987342j34kj3

我想输出类似的东西:

$numbers = 987342
$letter = j
$restofit = 34kj3

知道如何用PHP做到这一点?我可以使用preg_match吗?

1 个答案:

答案 0 :(得分:4)

没问题:

preg_match('/(\d+)([a-z])([a-z0-9]+)/', $string, $matches);

// First element of $matches is the entire matched string, ignore it
list(, $numbers, $letter, $restofit) = $matches;