Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用preg_match_all拆分外括号中包含数字的字符串_Php_Regex_Preg Match All - Fatal编程技术网

Php 如何使用preg_match_all拆分外括号中包含数字的字符串

Php 如何使用preg_match_all拆分外括号中包含数字的字符串,php,regex,preg-match-all,Php,Regex,Preg Match All,我有一个字符串,看起来像这样: 535354 345356 3543674 34667 2345347 -3536 4532452 (234536 2345634 -4513453) (2345 -13254 13545) ()之间的文本始终位于字符串的末尾(至少目前是这样) 我需要将其拆分为类似以下内容的数组: [0] => [0] 535354,345356,3543674,34667,2345347,-3536,4532452 [1] => [0] 234536,234563

我有一个字符串,看起来像这样:

535354 345356 3543674 34667 2345347 -3536 4532452 (234536 2345634 -4513453) (2345 -13254 13545)
()之间的文本始终位于字符串的末尾(至少目前是这样)

我需要将其拆分为类似以下内容的数组:

[0] => [0] 535354,345356,3543674,34667,2345347,-3536,4532452
[1] => [0] 234536,2345634,-4513453
    => [1] 2345,-13254,13545
preg_match_all应该使用什么表达式?
用我有限的知识,我能得到的最好结果是
/([0-9]{1,}){1,}.*(=(\(.*))/U
,但我仍然得到一些不需要的元素。

你可以在
preg\U match\U all
中使用这个正则表达式:

$re = '/\d+(?=[^()]*[()])/';

正则表达式分解:

\d+       # match 1 or more digits
(?=       # lookahead start
   [^()]* # match anything but ( or )
   [()]   # match ( or )
)         # lookahead end

您可以在
preg\u match\u all
中使用此正则表达式:

$re = '/\d+(?=[^()]*[()])/';

正则表达式分解:

\d+       # match 1 or more digits
(?=       # lookahead start
   [^()]* # match anything but ( or )
   [()]   # match ( or )
)         # lookahead end

您可以使用正则表达式来匹配括号外的数字块和括号内的数字块。(?您可以使用正则表达式来匹配括号外的数字块和括号内的数字块。(?)?