-1

I wrote src="([^"]+)" and it does the following matches : <img src="http://google.com/q.jpeg"> matched

<img alt="something" src="http://google.com/q.jpeg"> matched

<audio src="http://something.."> matched too

How can I exclude video and audio?

james lebron
  • 109
  • 1
  • 8

3 Answers3

1

Try This:

$sourcestring = '<img alt="something" src="http://google.com/q.jpeg">';
preg_match_all('/<img.*?src="(.*?)"/',$sourcestring,$matches);

print_r($matches[1]) 

is your output. It only accept tag src values.

this will helpful for you.

Yash
  • 1,446
  • 1
  • 13
  • 26
1
<img [^>]*src="([^"]+)"

Try this.Grab the capture or group.See demo.

https://regex101.com/r/gX5qF3/9

vks
  • 67,027
  • 10
  • 91
  • 124
1

A simple regex would be:

<img\b[^>]*?\bsrc\s*=\s*(['"])(.*?)\1

Demo

But remember, don't try this at home when better tools are available ;)

Community
  • 1
  • 1
Lucas Trzesniewski
  • 50,214
  • 11
  • 107
  • 158