Java Regex不会在多行中多次出现

时间:2014-11-29 01:14:52

标签: java regex

我正在尝试使用java regex span在多行上匹配[[1st-word | 2nd-word]][[word]]的文本模式。例如,我的代码是

String tStr = "Computer science in sport''' is an interdisciplinary discipline 
that has its goal in combining the theoretical as well as practical aspects 
and methods of the areas of [[Information technology|informatics]] and [[sport 
science]]. The main emphasis of the [[interdisciplinarity]] is placed on the 
application and use of computer-based but also mathematical techniques in sport 
science, aiming in this way at the support and advancement of theory and practice 
in sports.<ref>{{cite web|author=Daniel Link & Martin Lames|title=Sport 
Informatics – Historical Roots";

String validateRegex = "(\\[\\[)(:?)(\\w+)(\\|?)(\\w*)(\\]\\])";
Pattern pattern = Pattern.compile(validateRegex, Pattern.MULTILINE);
Matcher matcher = pattern.matcher(tStr);
while (matcher.find()) {
   System.out.println(matcher.group()+"\n");
}

输出[[interdisciplinarity]]。但是,我希望看到

[[Information technology|informatics]]
[[sport science]]
[[interdisciplinarity]]

有人可以帮助澄清我的错误在哪里吗?并举例说明如何正确提取预期的模式?

1 个答案:

答案 0 :(得分:0)

[[信息技术|信息学]]

[[运动科学]]

包含空格,在你的正则表达式中不存在。