我只是想写一个正确的正则表达式来从给定的html文本中获取图像的来源。
//HTML TEXT: <img src="angry.gif" alt="Angry face" />
var regEx = //regex Here
var source:Object = regEx.exec(htmlText);
答案 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);
}
快乐的代码!