我以字符串形式呈现了这个 HTML 部分。
<h1 id="Table1">Hello And welcome</h1>
<h1 id="Table2">Hello And welcome</h1>
<h1 id="Table3">Hello And welcome</h1>
<h1 id="Table4">Hello And welcome</h1>
我正在尝试从上述字符串中删除 id="*"
属性。所以最终的字符串应该只包含这个:
<h1>Hello And welcome</h1>
<h1>Hello And welcome</h1>
<h1>Hello And welcome</h1>
<h1>Hello And welcome</h1>
我正在使用 replaceAll()
方法,但无法构造正则表达式来执行此操作。请指教。
最佳答案
String result = subject.replaceAll("<h1 id=\"[^\"]*\">", "<h1>");
应该适用于这个简单的场景。
关于java - 如何替换字符串中的不同文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14251986/