开发者

Regex to detect numbers at start of string.

I have a string, consisting of: some numbers, a single letter, some numbers and letters.

F开发者_JAVA技巧or example: 987342j34kj3

I want to output something like:

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

Any idea how to do this with PHP? Can I use preg_match?


No problem:

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜