I have some code that processes a String and replaces the path for SRC attributes (from HTML) with a new path. But with certain attribute values the replaceAll method seems to go into an infinite loop rather than just not matching (or matching). If you run the following Java, rather than getting output for the modifiedString, it just appears to hang. Is this a legitimate bug with Java's replaceAll method or am I doing something wrong?
P.S. I am running Java 5 on Windows, in case it matters.
Code:
class ReplaceAllBugApp {
public static void main(String[] args) {
String originalString = new String("<img src=\"/images/subdir/company_logo_final.jpg />");
System.out.println("Original String: " + originalString); // Display the original string.
String modifiedString = originalString.replaceAll("(?i)src ?= ?\"((/?[\\w\\d\\-@%]+)*/)?([\\w\\d\\.\\_\\-@]+\\.[\\w\\d]+)\"", "src=\"/webapp/UserFiles/Images/$3\"");
System.out.println("Modified String: " + modifiedString); // Display the modified string.
}
}
P.S. I am running Java 5 on Windows, in case it matters.