正则表达式最小化匹配

有这么一段html,要匹配href标签

<a href="http://www1.test.io/">test</a><img src="./src/img.png"/><a href="http://www2.test.io/">test2</a><div class="test1">

 

错误方法:

href=".*"

匹配结果:

<a href="http://www1.test.io/">test</a><img src="./src/img.png"/><a href="http://www2.test.io/">test2</a><div class="test1">

 

正确的匹配方法:

 href=".+?" 

 

posted @ 2022-08-01 14:58  河在谈  阅读(65)  评论(0编辑  收藏  举报