Q:

Use Javascript's match function to extract part of a string

I am a sucker at Regular Expressions, I have learnt a few things about them but I can't get my head around them. There's part of a string that i need to extract from some HTML code but I don't know how to use regular expressions to do it.
I know that str.match() function takes in either a regular expression or a string and returns it. I would like to use this function to extract part of the string.
This is my code:
<img src="images/1.jpg" class="imgs" />
<img src="images/2.jpg" class="imgs" />
<img src="images/3.jpg" class="imgs" />

<script>
    var str = document.getElementsByClassName('imgs');  // str that is being matched
    var re = /^"images/.*"$/;
    var res = str[0].match(re);    // returns undefined is not a function
</script>

The 'images/1.jpg' is from an array that is sequential with the numbers. ie . 'images/1.jpg', 'images/2.jpg'.
I want to extract the "images/(num).jpg", whichever number it may be, i need to extract the "images" with the number. The final result should be "images/(num).jpg".
Is it possible to do it with str.match and regular expressions or some other technique should be used?

A:

if the image will always be a jpg you can do:
<img src="images/1.jpg" class="imgs" />
<img src="images/2.jpg" class="imgs" />
<img src="images/3.jpg" class="imgs" />

<script>
    var str = document.getElementsByClassName('imgs');  // str that is being matched
    var re = /images\/[0-9]+\.jpg/g
    var res = str[0].src.match(re)[0];    
</script>

this will return the string you're looking for.

