Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.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_带有特殊字符的所有拆分条件表达式_Php_Regex_Preg Match All - Fatal编程技术网

Php preg_match_带有特殊字符的所有拆分条件表达式

Php preg_match_带有特殊字符的所有拆分条件表达式,php,regex,preg-match-all,Php,Regex,Preg Match All,我有以下格式的数据: Randomtext1(#random2#, #random4#) == 1 && Randomtext2 (ran dom) != 2 || #Randomtext3# > 3 && Randomtext4 (random5,random7,random8) || Randomtext5 (Randomtext4 (random5,random7,random8), random10) < Randomtext11() 我获

我有以下格式的数据:

Randomtext1(#random2#, #random4#) == 1 && Randomtext2 (ran dom) != 2 || #Randomtext3# > 3 && Randomtext4 (random5,random7,random8) || Randomtext5  (Randomtext4 (random5,random7,random8), random10) < Randomtext11()
我获得:

0 => 'Randomtext1(#random2#, #random4#)',
1 => '1',
2 => 'Randomtext2 (ran dom)',
3 => '2',
4 => 'Randomtext3',
5 => '3',
6 => 'Randomtext4 (random5,random7,random8)',
7 => 'Randomtext5  (Randomtext4 (random5,random7,random8), random10)',
8 => 'Randomtext11()',
但我想:

0 => 'Randomtext1(#random2#, #random4#)'
1 => '1'
2 => 'Randomtext2 (ran dom)'
3 => '2'
4 => '#Randomtext3#'
5 => '3',
6 => 'Randomtext4 (random5,random7,random8)',
7 => 'Randomtext5  (Randomtext4 (random5,random7,random8), random10)',
8 => 'Randomtext11()',
我的问题是,我丢失了元素4的
#


有什么想法吗?

\w
0-9a-zA-Z
*您还需要允许
#
,您可以使用更改或字符类

[#\w]+

完整示例:

[#\w]+(?:\s*(\([^()]*+(?:(?1)[^()]*)*+\)))?
演示:

正则表达式演示:

\w代表“字字符”。它始终匹配ASCII字符[A-Za-z0-9]。请注意包含下划线和数字。在大多数支持Unicode的版本中,\w包含许多来自其他脚本的字符。关于实际包含的字符有很多不一致之处。通常包括字母和表意文字中的字母和数字。除下划线和数字符号以外的非数字连接器标点符号可能包括,也可能不包括。XML模式和XPath甚至包括\w中的所有符号


*

我想我应该在
preg\u split()
中使用这个更简单的模式。这对眼睛容易多了

代码:()()


这将匹配并拆分
==
&&
上的字符串=
|
问题,如果我想排除Randomtext4(random5,random7,random8),语法是什么?你可以使用
(*跳过)(*失败)
跳过。你试图消除的模式是什么,这个语法对我来说是有效的“~(和|或)+”(?:\s*([^()])*+(?:(?1)[^()]*)*+)+(跳过)(*失败)[\w]+(?:\s*([^()])+(?:(?1)[^())*+)+| |([[]\w]+)#但这是错误的?我可能可以用另一种方式写,但我需要知道目标是什么。另外,最好共享一个regex101链接,因为regex使用了很多字符,所以用于格式化。我想你的
[正则表达式也不正确。
(?:#|\w)+
[#\w]+(?:\s*(\([^()]*+(?:(?1)[^()]*)*+\)))?
$string='Randomtext1(#random2#, #random4#) == 1 && Randomtext2 (ran dom) != 2 || #Randomtext3# > 3 && Randomtext4 (random5,random7,random8) || Randomtext5  (Randomtext4 (random5,random7,random8), random10) < Randomtext11()';
var_export(preg_split('/ [=!&|<>]{1,2} /',$string));
array (
  0 => 'Randomtext1(#random2#, #random4#)',
  1 => '1',
  2 => 'Randomtext2 (ran dom)',
  3 => '2',
  4 => '#Randomtext3#',
  5 => '3',
  6 => 'Randomtext4 (random5,random7,random8)',
  7 => 'Randomtext5  (Randomtext4 (random5,random7,random8), random10)',
  8 => 'Randomtext11()',
)