我有这个内容,例如:
<?php echo $this->translate("Any text", "Any text next", "base-key") ?> Next string bla bla
string bla <?php echo $this->translate("SO Any text") ?>
enter code heretext bla <?php echo $this->translate("and string", null, "article-key") ?>
因此,我需要一个正则表达式,以匹配方法“ translate”的第一个和第三个参数中引号之间的文本。
输出可能看起来像这样:
array (
array (
0 => Any text,
1 => base-key
),
array (
0 => SO Any text,
1 => null
),
array (
0 => and string,
1 => article-key
),
)
我正在尝试以下表达式:
/translate\(["\'](.*?)["\']/s
我刚得到第一个参数字符串方法“ translate”
在此方面取得了一些成功:translate\(\"?(.*?)\"?(?:,\s?(?:\"?.*?\"?))?(?:,\s?\"?(.*?)\"?)?\)
。按照我的编写方式,如果第一个和第三个参数不在引号中,它还将捕获第一个和第三个参数,您可以通过删除第?
一个和第三个参数引号并将第一个参数设为可选来撤消该操作-translate\((?:\"(.*?)\")(?:,\s?(?:\"?.*?\"?))?(?:,\s?\"(.*?)\")?\)
可以在这里测试:https : //regex101.com/r/kG9eF3/1
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句