Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.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
Regex 如何使用正则表达式获取字符串中的方法/函数_Regex_Pcre - Fatal编程技术网

Regex 如何使用正则表达式获取字符串中的方法/函数

Regex 如何使用正则表达式获取字符串中的方法/函数,regex,pcre,Regex,Pcre,我正在尝试从字符串中的函数获取参数 参数可能包含: 例子 占位符: 功能 其他: 案例 下面是我正在处理的示例案例 内容: 正则表达式使用: 但是现在与正则表达式匹配的是 任何人都知道如何将参数置于@func\u strottime括号之间。如有任何回复,我将不胜感激。请尝试: (?<=@func_compare\().*?(?:\(.*?\).*?)?(?=\)) 您将使用递归正则表达式得到结果: (?<=@func_compare\()([^()]*\((?:.*?\)|(?

我正在尝试从字符串中的函数获取参数

参数可能包含:

例子 占位符:

功能

其他:


案例 下面是我正在处理的示例案例

内容:

正则表达式使用:

但是现在与正则表达式匹配的是

任何人都知道如何将参数置于@func\u strottime括号之间。如有任何回复,我将不胜感激。

请尝试:

(?<=@func_compare\().*?(?:\(.*?\).*?)?(?=\))

您将使用递归正则表达式得到结果:

(?<=@func_compare\()([^()]*\((?:.*?\)|(?1))*)[^()]*(?=\))

(?@CarySwoveland更新了我的问题。感谢您的回答。正则表达式无法获得预期匹配result@Deno感谢您的反馈。您希望一个统一的正则表达式同时适用于前一个字符串和新字符串吗?或者只适用于新字符串的解决方案是可以接受的?是的,需要同时适用于前一个字符串和新字符串。pos我在答案示例部分列出的可能匹配字符串。感谢您的及时回复。我已经相应地更新了我的答案。请您测试一下好吗?BR.再次感谢您的回复。您的答案几乎完美。只是无法涵盖诸如@func_compare('str',@func_test('1',@func_test('2'),'str',@func_test('3')之类的情况和@func_compare('str')、@func_test('1')、@func_test('2')、'str')我认为我的问题不能仅仅用正则表达式来解决。无论如何,感谢您的耐心和善意的帮助。
dERzUxOfnj49g/kCGLR3vhzBOTLwEMgrpa1/MCBpXQR2NIFV1yjraGVZLkujG63J0joj+TvNocjpJSQq2TpPRzLfCSZADcjmbkBkphIpsT8=
//Any string except brackets
@func_compare('string1',@func_test(2),1234),'Y-m-d H:i:s',@func_strtotime({{request.expires_in}} - 300)
(?<=@func_compare\().*[^\(](?=\))
'string1',@func_test(2),1234
'string1',@func_test(2),1234),'Y-m-d H:i:s',@func_strtotime({{request.expires_in}} - 300
(?<=@func_compare\().*?(?:\(.*?\).*?)?(?=\))
.*?(?:\(.*?\).*?)?(?=\))

.*?                       the shortest match not to overrun the next pattern
   (?:\(.*?\).*?)?        a group of substring which includes a pair of parens followed by another substring of length 0 or longer
                  (?=\))  positive lookahead for the right paren
(?<=@func_compare\()([^()]*\((?:.*?\)|(?1))*)[^()]*(?=\))