Java正则表达式数据修改

时间:2014-07-28 21:42:06

标签: java regex

我正在研究自动数据识别程序。该程序应该读取文本文件并修改某些行。举一个简单的例子,如果一个目录是“Folder / SubfolderZ / index.html”,我希望它改为“Folder / SubfolderX / index.html”。 “文件夹”包含各种子文件夹。 确切的问题有点复杂,但遵循相同的逻辑。

(编辑)的

Pattern pattern = Pattern.compile("<dt><li><a href=\"New folder/(1Visual Index|2Basic Charts|3Techniques, Interaction & Animation|4other|check)/(wimbledon_2012|azimuthal_projections|.)/index.html\" target=\"content\">.</a></li>");
Matcher matcher = pattern.matcher("<dt><li><a href=\"New folder/1Visual Index/box_plot/index.html\" target=\"content\">Box Plot</a>");

上面的代码没有给出匹配。我承认我对正则表达式没有多少经验。有人可以指出为什么代码不能正常工作吗?

1 个答案:

答案 0 :(得分:0)

只检查您要查找的内容。 尝试:

Pattern pattern = Pattern.compile("<a href=\"New folder/(1Visual Index|2Basic Charts|3Techniques, Interaction & Animation|4other|check)/([^/]++)/index\.html\" target=\"content\">");