如何解决正则表达式以匹配xml中的链接与最后一个mod
<?xml version='1.0' encoding='UTF-8'?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>https://google.com/2020/08/this1.html</loc><lastmod>2020-08-06T11:30:55Z</lastmod></url>
<url><loc>https://google.com/2020/08/this2.html</loc><lastmod>2020-08-05T11:30:06Z</lastmod></url>
<url><loc>https://google.com/2020/08/this3.html</loc><lastmod>2020-08-06T11:29:25Z</lastmod></url>
</lastmod></url></urlset>
我正在尝试从xml上方获取链接,以获取具有lastmod为2020-08-06的链接
我的正则表达式代码为 https:.+2020-08-05.+<\/url
但最终还是从第一个链接和最后一个链接获得了所有内容
我只想匹配
<url><loc>https://google.com/2020/08/this1.html</loc><lastmod>2020-08-06T11:30:55Z</lastmod></url>
<url><loc>https://google.com/2020/08/this3.html</loc><lastmod>2020-08-06T11:29:25Z</lastmod></url>
解决方法
一个非常简单而愚蠢的正则表达式-参见regexr:
.*<lastmod>2020-08-06.*
,
/<loc>(.+)<\/loc>.*2020-08-06/g
捕获loc标签之间的组 演示和说明在这里: https://regex101.com/r/HBvG3K/8
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。