简体   繁体   English

regex / preg_match在数字和字母之间交替,并用空格分隔

[英]regex/preg_match alternating between numeric and alpha separated by space

My string separates digits and alpha (phrases) by space. 我的字符串用空格分隔数字和字母(短语)。 The digits and alpha alternate. 数字和字母交替。 So in the example below there are 6 ACT YE. 因此,在下面的示例中有6个ACT YE。 And the string continues with another set of digit then alpha. 字符串继续输入另一组数字,然后是alpha。

Can't seem to get the right pattern to do the following... 似乎无法获得正确的模式来执行以下操作...

Example String: 6 ACT YE 1000 FH 6 ACT YE 10000 ACT FC 32000 ACT 示例字符串:6 ACT YE 1000 FH 6 ACT YE 10000 ACT FC 32000 ACT

Should come out like: 应该出来像:

[0] = 6
[1] = ACT YE
[2] = 1000
[3] = FH
[4] = 6
[5] = ACT YE
[6] = 10000
[7] = ACT FC
[8] = 32000
[9] = ACT

Try this: 尝试这个:

$result = preg_split("/(?<=\d)\s+(?=\D)|(?<=\D)\s+(?=\d)/",$input);

This splits the subject string on spaces, but only if exactly one of "the stuff before" and "the stuff after" is a digit. 这会在空格处分割主题字符串,但前提是“前”和“后”中的一个恰好是一个数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM