假设我有几行维基百科 XML 如下所示:
[[Image:ChicagoAnarchists.jpg|thumb|A sympathetic engraving by [[Walter Crane]] of the executed "Anarchists of Chicago" after the [[Haymarket affair]]. The Haymarket affair is generally considered the most significant event for the origin of international [[May Day]] observances]] In 1907, the [[International Anarchist Congress of Amsterdam]] gathered delegates from 14 different countries, among which important figures of the anarchist movement, including [[Errico Malatesta]]
我想删除以 [[Image:”开头并以“observances]]
结尾的行。
可能还有其他几行带有方括号的文本,我不想进行贪婪搜索,否则它也可能会不小心删除其他方括号。
例如,如果我只是做了一个贪婪的 \\[\\[Image:.*\\]\\]
,我相信它会删除最后一个右括号之前的所有内容(Ericco马拉泰斯塔)
是否有正则表达式可以让我更轻松地完成这项工作?
最佳答案
让我们看看...使用惰性重复而不是贪婪重复怎么样?
\[\[Image:.*?observances\]\]
关于java - Java 中的什么正则表达式可以捕获并删除此模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7974595/