import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<=_)[12]\\d{3}_[01]\\d_[0123]\\d(?=_)";
final String string = "CRC_recup_backup_2018_11_20_004003_1817970.bak\n"
+ "CRC_recup_backup_2018_11_21_004001_6027986.bak\n"
+ "CRC_recup_backup_2018_11_22_004001_7717997.bak\n"
+ "CRC_Test_backup_2018_11_16_004002_9068137.bak";
final String subst = "2020_08_09";
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