我有一个字符串,其中包含一些值,如下所示。我想用一些新文本替换包含特定customerId的html img标签。我想这是不是给我的期望output.here是节目信息小型的Java程序为什么这个正则表达式没有给出预期的输出?
我输入的字符串
String inputText = "Starting here.. <img src=\"getCustomers.do?custCode=2&customerId=3334¶m1=123/></p>"
+ "<p>someText</p><img src=\"getCustomers.do?custCode=2&customerId=3340¶m2=456/> ..Ending here";
正则表达式是
String regex = "(?s)\\<img.*?customerId=3340.*?>";
新的文本,我想把里面输入串
编辑启动:
String newText = "<img src=\"getCustomerNew.do\">";
编辑完:
我现在做
String outputText = inputText.replaceAll(regex, newText);
输出
Starting here.. Replacing Text ..Ending here
但我预计产量
Starting here.. <img src=\"getCustomers.do?custCode=2&customerId=3334¶m1=123/></p><p>someText</p>Replacing Text ..Ending here
请注意在我的预期输出中,只有包含customerId = 3340的img标签被替换文本替换。我没有得到为什么在输出我得到这两个img标签获得replced?
你解析与正则表达式,只是从未工程完全的HTML(这是一般不是你regexing技能正则表达式的限制) –
你使用的是错误的tool..use HTML解析器 – Anirudha
@ Some1.Kill.The.DJ你能帮我一下,我怎样才能得到像jsoup这样的html解析器的预期结果? –