With this string:
<?php
"<img src=\"1.jpg\" /><img src=\"2.jpg\" alt=\"2\" />"
?>
I am trying to add a string like "alt=\"1\"" to only the img tag that does NOT already have an alt property
This regex matches the src property just like I want it to:
"/(<\s*img\s*src\s*=\s*[\"|'](.+?)[\"|'])/"
But when I try to match the end tag without any other characters, it gets greedy and matches the quote from the end of the alt property:
"/(<\s*img\s*src\s*=\s*[\"|'](.+?)[\"|'])\s*\/>/"
So, is there a way to implement this regex where the .+? won't match the middle quotes?
Or, what is a good way to match the img tag that doesn't have an alt property?
I know I could do it with two statements, but it seems like it should be possible with just one.
Thanks.