我有一些HTML:
<ul>
<li>First Test (EOL)
</li>
<li>Second Test</li>
</ul>
我想删除带有EOL字符的FIRST li组件。
我试过这个(我也在\ r和\ n上使用了单个转义符):
String returnString = theHTMLFromMethod;
String test = "<li>" + firstWord + " " + secondWord+ "(\\\\r|\\\\n)" + "</li>";
System.out.println(test);
returnString = returnString.replaceAll(test, "");
但它不起作用。我在这里做错了什么?
答案 0 :(得分:1)
以下是工作示例:
class Test {
public static void main(String[] args) {
String sourceString = "PREFIX <li>Some text\n</li> SUFFIX";
String regularExpression = "<li>Some text(\n|\r|\r\n)</li>";
System.out.println("Source string: " + sourceString);
System.out.println("Regular expression: " + regularExpression);
System.out.println("Eval result: " + sourceString.replaceAll(regularExpression, ""));
}
}