kymbrik
9/18/2017 - 10:12 AM

JS RegExp Src Img Extractor

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script>
        function parse()
        {
            var str = document.getElementById("source").value;
            var myRegexp = /<img[^>]*src="([^"]*)"/g;
            match = myRegexp.exec(str);
            while (match != null) {
                // matched text: match[0]
                // match start: match.index
                // capturing group n: match[n]
                console.log(match[1]);
                match = myRegexp.exec(str);
            }
        }
    </script>
</head>
<body>
<textarea id="source" rows="30" cols="65" name="text"></textarea>
<input type="submit" value="extract" onclick="parse()">
<textarea id="result" cols="65" rows="30"></textarea>
</body>
</html>