Code:
<script type="text/javascript">
<!--
var teststring = '<img src="dir/cas.jpg"><img src="dir/ast.jpg">';
function fetch_image_names(code)
{
matches = new Array();
while (code.match(/(<img src="dir\/(.+?)\.jpg">)/i))
{
matches.push(RegExp.$2);
code = code.replace(RegExp.$1, '', code);
}
return matches;
}
alert('The string yielded the following results: ' + fetch_image_names(teststring).join(','));
-->
</script>
Should do the job for you, following the exact code you posted that is.