I tried many ways to do this. And I am totally new to Regular expression. I want to replace all img src link to other link.
My html file just are like this:
<img src="01"></img><img src="02"></img><img src="03"></img>
or it would be like this:
< img src = "01"></img>< img src="02">< img src = "03"></img>
There might be space or just without "</img>
"
and I want them be like this way:
<div><p><DIV class="a"><img src="01"></img></p></div><div><p><DIV class="a"><img src="02"></img></p></div><div><p><DIV class="a"><img src="03"></img></p></div>
and I use this to get the img src link:
Pattern p = null;
Matcher m = null;
p = Pattern.compile("<img[^>]*src\\s*=\\s*\"([^\"]*)");
m = p.matcher(mystr);
while (m.find()) {
imgIDList.add(m.group(1));
}
and I made the str list to replace: ArrayList imgList4Replace = new ArrayList();
and I use this to excuse replace :
mystr.replace(("<img[^>]*src\\s*=\\s*\""+imgListReplaceOriginal.get(nIndex)+"([^\"]*)"), imgList4Replace.get(nIndex)+"$2");
it just don't work. I've spent so much time to test.
And need your help. Thank you very much.