import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\/\\*(?:.|\\n)*?GNU General Public License(?:.|\\n)*?\\*\\/|\\\"use strict\";";
final String string = "/* \n"
+ " * This file is part of OverPy (https://github.com/Zezombye/overpy).\n"
+ " * Copyright (c) 2019 Zezombye.\n"
+ " * \n"
+ " * This program is free software: you can redistribute it and/or modify \n"
+ " * it under the terms of the GNU General Public License as published by \n"
+ " * the Free Software Foundation, version 3.\n"
+ " *\n"
+ " * This program is distributed in the hope that it will be useful, but \n"
+ " * WITHOUT ANY WARRANTY; without even the implied warranty of \n"
+ " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU \n"
+ " * General Public License for more details.\n"
+ " *\n"
+ " * You should have received a copy of the GNU General Public License \n"
+ " * along with this program. If not, see <http://www.gnu.org/licenses/>.\n"
+ " */\n\n"
+ "\"use strict\";\n\n"
+ "astParsingFunctions[\"_&addToScore\"] = function(content) {\n\n"
+ " if (enableOptimization) {\n"
+ " if (content.args[0].name === \"__number__\" && content.args[0].args[0].numValue === 0) {\n"
+ " return getAstForUselessInstruction();\n"
+ " }\n"
+ " }\n"
+ " \n"
+ " return content;\n"
+ "}";
final String subst = "";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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