Note that there are some explanatory texts on larger screens.

plurals
  1. PORegular expression how to replace the src link in img tag
    primarykey
    data
    text
    <p>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.</p> <p>My html file just are like this:</p> <pre><code>&lt;img src="01"&gt;&lt;/img&gt;&lt;img src="02"&gt;&lt;/img&gt;&lt;img src="03"&gt;&lt;/img&gt; </code></pre> <p>or it would be like this:</p> <pre><code>&lt; img src = "01"&gt;&lt;/img&gt;&lt; img src="02"&gt;&lt; img src = "03"&gt;&lt;/img&gt; </code></pre> <p>There might be space or just without "<code>&lt;/img&gt;</code>"</p> <p>and I want them be like this way:</p> <pre><code>&lt;div&gt;&lt;p&gt;&lt;DIV class="a"&gt;&lt;img src="01"&gt;&lt;/img&gt;&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;DIV class="a"&gt;&lt;img src="02"&gt;&lt;/img&gt;&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;DIV class="a"&gt;&lt;img src="03"&gt;&lt;/img&gt;&lt;/p&gt;&lt;/div&gt; </code></pre> <p>and I use this to get the img src link:</p> <pre><code> Pattern p = null; Matcher m = null; p = Pattern.compile("&lt;img[^&gt;]*src\\s*=\\s*\"([^\"]*)"); m = p.matcher(mystr); while (m.find()) { imgIDList.add(m.group(1)); } </code></pre> <p>and I made the str list to replace: ArrayList imgList4Replace = new ArrayList();</p> <p>and I use this to excuse replace :</p> <pre><code> mystr.replace(("&lt;img[^&gt;]*src\\s*=\\s*\""+imgListReplaceOriginal.get(nIndex)+"([^\"]*)"), imgList4Replace.get(nIndex)+"$2"); </code></pre> <p>it just don't work. I've spent so much time to test.</p> <p>And need your help. Thank you very much.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload