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
Php 从Wiki XML语法提取图像路径_Php_Regex - Fatal编程技术网

Php 从Wiki XML语法提取图像路径

Php 从Wiki XML语法提取图像路径,php,regex,Php,Regex,我尝试解析从XML中获取的WikipediaXML 在一种情况下,我需要提取所有图像路径。原始标记看起来像 [[Bild:nameOfImage.png|image description]] “Bild”也可以是“图像”、“文件”或“日期” 为了提取图像的文本,我使用这个正则表达式 '|\[\[.*\|.*\]\]|U' 如果图像描述中不是另一个“[[…]]”的话,这很好,比如 [[Bild:nameOfImage.png|image Description with a [[new

我尝试解析从XML中获取的WikipediaXML

在一种情况下,我需要提取所有图像路径。原始标记看起来像

  [[Bild:nameOfImage.png|image description]]
“Bild”也可以是“图像”、“文件”或“日期”

为了提取图像的文本,我使用这个正则表达式

'|\[\[.*\|.*\]\]|U'
如果图像描述中不是另一个“[[…]]”的话,这很好,比如

[[Bild:nameOfImage.png|image Description with a [[new wiki link]] ]]
我的问题是,如何修改正则表达式以获得第一个“[[”和最后一个“[/strong>”]]”之间的all文本,而不计算所有“['an']”字符


提前感谢

因为您使用的是PHP,所以您可能能够使用它。
考虑到你没有捕获任何东西:

/\[\[(((?>[^\[\]])|(?R))*)\]\]/U
注意,我没有尝试过这个正则表达式,因为我没有办法使用PHP

编辑:

preg_match('/\[\[(?>[^\[\]]|(?R))*\]\]/U', '[[Bild:nameOfImage.png|image Description with a [[new wiki link]] ]]', $array);
var_dump($array);

似乎有用。

耶!非常感谢!!:)