import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "[^.]+\\.(?=[^.]+$)";
final String string = "// hash starts with number\n"
+ "/css/app.style.7fef363d5a8c4ef2458c.css\n"
+ "/css/app.bundle.7fef363d5a8c4ef2458c.css\n"
+ "/css/app.chunk.7fef363d5a8c4ef2458c.css\n"
+ "/css/app.7fef363d5a8c4ef2458c.css\n"
+ "/css/loading-animation.7fef363d5a8c4ef2458c.css\n\n"
+ "// hash starts with letter\n"
+ "/css/app.style.b3bcb606396f0c96623a.css\n"
+ "/css/app.bundle.b3bcb606396f0c96623a.css\n"
+ "/css/app.chunk.b3bcb606396f0c96623a.css\n"
+ "/css/app.b3bcb606396f0c96623a.css\n\n"
+ "// no preceeding dot separated name before the hash\n"
+ "/css/loading-animation.b3bcb606396f0c96623a.css\n"
+ "/css/app.b3bcb606396f0c96623a.js";
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