同一行中锚标记的正则表达式
Regular expression for anchor tags in same line
/<a .*href.*>/ig
是一个简单的正则表达式,它选择像这样的字符串:
<a href>
<a href="www.example.com">
<a href="http://www.google.com" target="_blank">click me</a>
<a href="www.google.com" > click me</a>
<A href="www.123-xyz.com" > click me</a>
但是它也选择以下作为单个字符串:
<a href="www.google.com" target="_blank"> www.google.com</a><a href="www.google.com" >click me</a>
有什么方法可以将以上内容选为 2 个不同的字符串,如:
<a href="www.google.com" target="_blank"> www.google.com</a>
<a href="www.google.com" >click me</a>
<a\s[^>]*>
希望对您有所帮助。
你的*
量词贪心;让他们 *?
不情愿(消耗尽可能少的输入来匹配):
/<a .*?href.*?>/ig
参见demo。
/<a .*href.*>/ig
是一个简单的正则表达式,它选择像这样的字符串:
<a href>
<a href="www.example.com">
<a href="http://www.google.com" target="_blank">click me</a>
<a href="www.google.com" > click me</a>
<A href="www.123-xyz.com" > click me</a>
但是它也选择以下作为单个字符串:
<a href="www.google.com" target="_blank"> www.google.com</a><a href="www.google.com" >click me</a>
有什么方法可以将以上内容选为 2 个不同的字符串,如:
<a href="www.google.com" target="_blank"> www.google.com</a>
<a href="www.google.com" >click me</a>
<a\s[^>]*>
希望对您有所帮助。
你的*
量词贪心;让他们 *?
不情愿(消耗尽可能少的输入来匹配):
/<a .*?href.*?>/ig
参见demo。