php中的正则表达式从以下html代码中提取图像src [重复]

This question already has an answer here:

i need regular expression in php to extract image src from following html code

<img class=" wp-image " width="300" height="218" alt="anything" src="image url"></img>

</div>

You should use an HTML parser for this. Nevertheless, you can do it using regex with something like this:

<img[^>\/]*src=("(?:[^\"]*)"|'(?:[^\']*)')

The image url would be in capture group 1.

Edit: If you also want to get unqouted src's you can use this:

<img[^>\/]*src=("(?:[^\"]*)"|'(?:[^\']*)'|(?:[^=<>\s\"\'`]+))