我试图从字符串中的函数获取参数。
参数可能包含:
示例
占位符:
{{request.expires_in}}
//can match regex: \{\{[a-zA-z0-9\.\-\_]\}\}
函数
@func_compare('string1','string2',1234)
其他:
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_strtotime 括号之间的参数。我将不胜感激任何回应。
最佳答案
请您尝试一下:
(?<=@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
关于regex - 如何使用正则表达式获取字符串中的方法/函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60647106/