I have a regex pattern expected to capture the src and height (which is possibly in the height
or style
attribute) from some <img>
html elements. Here is my pattern:
/img[^\>]*(?:height="([\d]+)")?[^\>]*src="([^"]+)"[^\>]*(?:style\="height:([\d]+)px;?[^"]+")?[^\>]*/i
I use the preg_match_all
function to search for the following string:
<img alt="" height="200" src="http://www.example.com/example.png" width="1500" style="height:200px;" />
There is no problem with src, but it cannot capture the height subgroups. Am I wrong with the regex pattern?