Implementation: Through JS regular match out all pictures and all pictures address src.
Train of thought: 1. Match the image of the IMG tag (that is, match all the pictures), filter other unwanted characters
2. From the matching result (in the IMG tag) loop match out the picture address (that is, SRC attribute)
Code: (You can copy it to the local test)
The code is as follows |
Copy Code |
<script type= "Text/javascript" > The idea is divided into two steps: the author (yanue). 1, matching out the image of the IMG tag (that is, match all the pictures), filter other unwanted characters 2. From the matching result (in the IMG tag) loop match out the picture address (that is, SRC attribute) var str = "This is test string 123" and " 33! Matching picture (g means match all results I indicates case-sensitive) var Imgreg =/|/>)/gi; Match src attribute var srcreg =/src=[' "]? ([^'"]*) [' "]?/i; var arr = Str.match (Imgreg); Alert (' array of all successfully matched pictures: ' +arr '); for (var i = 0; i < arr.length; i++) { var src = arr[i].match (srcreg); Get Picture Address if (Src[1]) { Alert (' Matching picture address ' + (i+1) + ': ' +src[1]); } Of course you can also replace the SRC attribute if (Src[0]) { var t = src[0].replace (/src/i, "href"); Alert (t); } } </script> |