-4

Please, what is the correct php code, using a regex pattern, to get $output from $string?

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

Generalizing:

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

Brackets can be recursive (as text()). i.e. string1_1 and/or string2_1 may contain other brackets. $string = 'string1(string1_1())string2(string2_1()string2_2());

Knowing the brackets prefix xmlns, I need the regex pattern to get //section/datePublished/text(), i.e. knowing string1I need the regex pattern to get string1_1 (or string1_1()).

Knowing the brackets prefix xpointer, I need the regex pattern to get ns=http://testurl.com/now, i.e. knowing string2I need the regex pattern to get string2_1 (or string2_1()string2_2().

Can you explain the process?

4

1 回答 1

0

这可以帮助

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

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

于 2018-12-01T09:16:48.623 回答