您好,我想在 HTML 中找到该代码
{%foreach damagePhotos : photo%}
<img src="{%=photo}" alt="" width="320" height="200"/>
{%endforeach%}
我的正则表达式是:
Matcher matcher = Pattern.compile("\\{\\%foreach\\s(.*)\\s:\\s(.*)\\%\\}\\s(.*)\\s\\{\\%endforeach\\%\\}",Pattern.MULTILINE).matcher(parsedHtml);
一切正常,直到我在 html 中得到了很多这样的模式 :(
例如:
<p>
{%foreach carPhotos : photo%}
<img src="{%=photo}" alt="" width="320" height="200"/>
{%endforeach%}
</p>
<p>
{%foreach damagePhotos : photo%}
<img src="{%=photo}" alt="" width="320" height="200"/>
{%endforeach%}
</p>
然后 mather 找到一个匹配项,group(1) 是:
carPhotos : photo%} <img src="{%=photo}" alt="" width="320" height="200"/> {%endforeach%}</p><p> {%foreach damagePhotos
我的正则表达式有什么问题?
最佳答案
关于Java 模式多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50241917/