So I am trying to remove all the content between two strings (including the two strings) and I can't figure out why my code is not working. I even tested it on this website: http://www.regexplanet.com/advanced/java/index.html
And their "replaceAll()" section has the exact string I'm expecting, but what I get on my Android app is the entire original string with no changes. I have tried different methods based on examples found on this site such as:
String thematch = Pattern.quote("<p>Listen") + "(.*?)" + Pattern.quote("</audio></p>");
String thenew = thecontent.replaceAll(thematch, "");
And:
String thenew = thecontent.replaceAll("<p>Listen(.*?)</audio></p>","");
Neither are replacing the string. What's going on?
Edit: Fixed by adding (?s) to the beginning of thematch as anubhava said.
You need s
flag (DOTALL) that lets you match .
newlines also:
String thematch = "(?s)" + Pattern.quote("<p>Listen") + "(.*?)" + Pattern.quote("</audio></p>");
However as a word of caution you should use a HTML/XML parser for manipulating HTML documents.