Note that there are some explanatory texts on larger screens.

plurals
  1. PORegex to remove spaces from file name
    text
    copied!<p>I have some html strings which contains images. I need to remove <strong>spaces</strong> from <strong>image name</strong> because some tablets do not accept them. (I already renamed all image resources). I think the only fix part is ... </p> <pre><code>src="file:///android_asset/images/ ?? ?? .???" </code></pre> <p>because those links are valid links.</p> <p>I spent half day on it and still struggling on performance issue. The following code works but really slow...</p> <pre><code>public static void main(String[] args) { String str = "&lt;IMG height=286 alt=\"eye_anatomy 1.jpg\" src=\"file:///android_asset/images/eye_anatomy 1 .jpg\" width=350 border=0&gt;&lt;/P&gt; fd ssda f \r\n" + "fd &lt;P align=center&gt;&lt;IMG height=286 alt=\"eye_anatomy 1.jpg\" src=\"file:///android_asset/images/ eye_anato my 1 .bmp\" width=350 border=0&gt;&lt;/P&gt;\r\n" + "\r\n&lt;IMG height=286 alt=\"eye_anatomy 1.jpg\" src=\"file:///android_asset/images/eye_anatomy1.png\" width=350 border=0&gt;\r\n"; Pattern p = Pattern.compile("(.*?)(src=\"file:///android_asset/images/)(.*?\\s+.*?)(\")", Pattern.DOTALL); Matcher m = p.matcher(str); StringBuilder sb = new StringBuilder(""); int i = 0; while (m.find()) { sb.append(m.group(1)).append(m.group(2)).append(m.group(3).replaceAll("\\s+", "")).append(m.group(4)); i = m.end(); } sb.append(str.substring(i, str.length())); System.out.println(sb.toString()); } </code></pre> <p><strong>So the real question is, how can I remove spaces from image name efficiently using regex.</strong></p> <p><strong>Thank you.</strong></p>
 

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