import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "<a.*?href=\\\"(.+?.pdf\\?min)\\\".*?>(.*?)<\\/a>";
final String string = "<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" border=\"0\">\n"
+ " <tbody>\n"
+ " <tr>\n"
+ " <td width=\"25%\"><a href=\"http://www.test.com/myfile.pdf?min\" target=\"_blank\">Menus 18 €</a></div></td>\n"
+ " <td width=\"25%\"><a href=\"http://www.test.com/myfile.pdf?min\" target=\"_blank\">Menus 24 et 26 €</a></div></td>\n"
+ " <td width=\"25%\"><a href=\"http://www.test.com/myfile.pdf?min\" target=\"_blank\">Menus 30 et 37 € </a></div></td>\n"
+ " <td width=\"25%\"><a href=\"http://www.test.com/myfile.pdf?min\">La Carte détaillée <br>\n"
+ " (Entrées - Viandes - Poissons)</a></td>\n"
+ " </tr>\n"
+ " </tbody>\n"
+ "</table>";
final String subst = "ok";
final Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html