Reputation: 1708
I'm trying to fix a bug on a WP Plugin. It uses this expression to parse the urls:
$anchorPattern = '/\'\"\/\/([^\'\"]+?)\'\">(.*?)</a>/i';
The problem is with the mailto: urls, which are not being matched correctly. So for example, when the code is like:
<a href="mailto:[email protected]" target="_blank"><img src="email.png"></a>
The 2nd match is
mailto:[email protected]" target="_blank"><img src="http:
because the regex only stops at the //. How to I change the regex expression to get the 2nd match to be 'mailto:' ?
regex testing here: http://regex101.com/r/sY4bW8
Upvotes: 0
Views: 326
Reputation: 98961
Vê se é isso que vc quer:
preg_match('/<a.*?href=["\'](.*?)["\'].*?><img.*?src=["\'](.*?)["\'].*?>/i', $html)
Grupo 1 é o url
Grupo 2 a source da imagem.
Upvotes: 1
Reputation: 32189
You can modify your regex as follows:
<a (.*?)href=[\'\"](.*?:)([^\'\"]+?)[\'\"](.*?)>(.*?)<\/a>
Now it will match mailto:
.
Upvotes: 1