• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1220
  • Last Modified:

Using Regular Expressions to retrive HTML Attribute Value

Is there a way to select only the value of a specific attribute in a specific html tag.

eg. <img id="test" src="test2">

I would like to only return the "src" value which is "test2"

Thanks in advance
0
minotaur01
Asked:
minotaur01
  • 2
2 Solutions
 
ddrudikCommented:
as capture group 0:
(?<=<img id="test" src=")[^"]*(?=">)

or with capture group 1:
<img id="test" src="([^"]*)">
0
 
ozoCommented:
<img\b(?:[^<>"]+|"[^"]*")*\bsrc=("[^"]*")(?:[^<>"]+|"[^"]*")*>
0
 
ddrudikCommented:
Thanks for the question and the points.
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now