我正在尝试匹配多行文本格式[[1st-word | 2nd-word]]
或[[word]]
使用Java正则表达式跨多行。例如,我的代码是
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]]
有人可以帮我弄清楚我的错误在哪里吗?并举一个例子,我如何正确地提取期望的模式?
[[信息技术|信息学]]
和
[[体育科学]]
包含您的正则表达式中不存在的空间。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句