获得具有特定前缀的递归括号的正则表达式模式是什么?



请问,使用正则表达式模式从$string获取$output的正确 php 代码是什么?

$string = 'xmlns(ns=http://testurl.com/now)xpointer(//section/datePublished/text())';

推广:

$string = 'string1(string1_1)string2(string2_1)';

括号可以是递归的(如text())。 即string1_1和/或string2_1可能包含其他括号。 $string = 'string1(string1_1())string2(string2_1()string2_2());

知道括号前缀xmlns,我需要正则表达式模式来获取//section/datePublished/text(),即知道string1我需要正则表达式模式来获取string1_1(或string1_1())。

知道括号前缀xpointer,我需要正则表达式模式来获取ns=http://testurl.com/now,即知道string2我需要正则表达式模式来获取string2_1(或string2_1()string2_2()。

你能解释一下这个过程吗?

这会有所帮助

preg_match('/xmlns((.*))xpointer((.*))/', $inString, $outArray);
$output = $outArray[2];
$output1 = $outArray[1];

演示:https://www.phpregexonline.com/q/4

最新更新