I want to get first src attribute, I am using this regex but it scraping all src attribute:
(?<=src=").*?(?=")
Example:
<img src="http://ia.media-imdb.com/images/M/MV5BMTY3NjY0MTQ0Nl5BMl5BanBnXkFtZTcwMzQ2MTc0Mw@@._V1_SY317_CR0,0,214,317_AL_.jpg" />
<img src="http://ia.media-imdb.com/images/M/MV5BMjAzODk4OTI3Ml5BMl5BanBnXkFtZTgwMzU2MTY0MzE@._V1_SX86_CR0,0,86,86_AL_.jpg" />
<img src="http://ia.media-imdb.com/images/M/MV5BNzUzNzY1NzQxM15BMl5BanBnXkFtZTgwMTM0MTY0MzE@._V1_SY86_CR33,0,86,86_AL_.jpg" />
<img src="http://ia.media-imdb.com/images/M/MV5BMTAxNTAwMTg0ODReQTJeQWpwZ15BbWU4MDMzNDE2NDMx._V1_SY86_CR33,0,86,86_AL_.jpg" />
You could get the value of first
img src
attribute in two ways.Through capturing group.
Grab the value of
img src
attribute from group index 1.DEMO
Through
\K
and positive lookahead assertion.Grab the value of
img src
attribute from group index 0.DEMO