Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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
Java 从xml文件中的文本解析内部链接_Java_Regex_Xml Parsing - Fatal编程技术网

Java 从xml文件中的文本解析内部链接

Java 从xml文件中的文本解析内部链接,java,regex,xml-parsing,Java,Regex,Xml Parsing,我需要获得维基新闻xml文件文本字段中的内部链接 在我的例子中,它们有两种格式 [[w:President of the People's Republic of China|President]] [[People's Republic of China]] 我应用了这些正则表达式模式 internalLinks = Pattern.compile("\\[\\[w:([^|:]+)\\|.*\\]\\]").matcher(internalLinks).replaceAll("##en.

我需要获得维基新闻xml文件文本字段中的内部链接

在我的例子中,它们有两种格式

[[w:President of the People's Republic of China|President]]
[[People's Republic of China]] 
我应用了这些正则表达式模式

internalLinks = Pattern.compile("\\[\\[w:([^|:]+)\\|.*\\]\\]").matcher(internalLinks).replaceAll("##en.wikipedia.org/wiki/$1##");        

internalLinks = Pattern.compile("\\[\\[([^:|]+)\\]\\]").matcher(internalLinks).replaceAll("[[[en.wikinews.org/wiki/$1]]]");



    Pattern pattern = Pattern.compile("\\[\\[\\[(.*?)\\]\\]\\]");
    Matcher matcher = pattern.matcher(internalLinks);
    while (matcher.find()) 
    {           
            interLinks += matcher.group(1)+",";
    }


    Pattern pattern1 = Pattern.compile("##(.*?)##");
    Matcher matcher1 = pattern1.matcher(internalLinks);
    while (matcher1.find()) 
    {           
            interLinks += matcher1.group(1)+",";
    }

    if (interLinks.length() > 0) {
        interLinks = interLinks.substring(0, interLinks.length()-1);
        return interLinks;
    } else return "";
问题是,它只是给我的链接匹配第一模式,太少的链接,只有3-4,而不是全部

这里我提供了一个文档文本字段的摘录

{{日期| 2004年11月13日} {{巴西}[[w:胡锦涛|胡锦涛]],中华人民共和国的[[w:中华人民共和国总统|主席]]今天在巴西的[[w:巴西总统|总统]][[w:路易斯·伊纳西奥·卢拉·达席尔瓦]]总统官邸格兰杰·托尔托(Granja Torto)共进午餐[[w:巴西联邦区|巴西联邦区]]午餐是传统的巴西人午餐[[w:烧烤|烧烤]]有不同种类的肉

一些巴西部长出席了会议:[w:安东尼奥·帕洛西|安东尼奥·帕洛西]](经济),[[w:pt:爱德华多·坎波斯|爱德华多·坎波斯]([[w:科学和技术部(巴西)|科学和技术]],[[w:乔·罗伯托·罗德里格斯|罗伯托·罗德里格斯]](农业),[[w:pt:路易斯·费尔南多·富兰](发展)[[w:Celso Amorim | Celso Amorim][[w:

对外关系(巴西)|对外关系]]、[[w:Dilma Rousseff | Dilma Rousseff]](矿产和能源)。出席会议的还有[[w:pt:Roger Agnelli | Roger Agnelli]]([[w:Vale(矿业公司)| Vale do Rio Doce]]公司总裁)和Eduardo Dutra([[w:Petrobras | Petrobras]],政府石油公司总裁)

这次会议是巴西和中国之间新的[[w:政治经济|政治经济]]协议的一部分,巴西承认中国大陆的[[w:社会主义市场经济|市场经济]]地位,中国承诺购买更多[[w:巴西经济|巴西产品]]


我访问了下载页面,页面顶部写着:

有关提供的数据格式的文档,请参见转储

我想他们提供了比普通正则表达式更好的解析方法,请查看…

解决方案 描述

讨论 此正则表达式假定字符序列
]
不会出现在
[[
]
之间。 我现在无法找到
]
的转义序列

演示

您能提供一个指向Wikinews xml文件示例的链接吗?这是我在enwikinews-20131030-pages-meta-current上获取的链接。xml@Alex我已经从文本字段中包含了一段内容。请告诉我出了什么问题
\[\[(?:w:)?.*?\]\]