如何在AS3中使用RegularExpressions获取图像源?

时间:2011-06-27 11:32:20

标签: regex actionscript-3

我只是想写一个正确的正则表达式来从给定的html文本中获取图像的来源。

//HTML TEXT: <img src="angry.gif" alt="Angry face" />

var regEx = //regex Here

var source:Object = regEx.exec(htmlText);

2 个答案:

答案 0 :(得分:3)

var regex:RegEx  = /src="(.*?)"/i;
var source:String = regex.exec(htmlText)[1];

答案 1 :(得分:0)

    var str:String="Content <img src='imagePath01.jpg' width='88' height='88'/> content content content <img src='imagePath01.jpg' width='88' height='88'/>";
        var imgRegExp:RegExp = /<img[^>]+>/g;//Get (add 'g' end regex) all img in content;
        var imgArr:Array = str.match( imgRegExp );
            for(var i:uint=0;i<imgArr.length;i++){
                trace(imgArr[i]);
                //Get src from img;
                var imgXML:XML = XML(imgArr[i]);
                trace("src: "+imgXML.@src);
            }

快乐的代码!