import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^.+ (?:full|incr|manual) .+? (.+?) .*";
final String string = "rspedw03.corpads.local 3085876532 JC_UNIX_FS01_INCR_DD2 JC_FS_DD2 UNIX_FS01_INCR_DD2 incr 02/23/2022 03/29/2022 03/29/2022 disk 1645592426 backup 3013 MB JCBDD2301P.CORPADS.LOCAL\n"
+ "rsuedw01.corpads.local 1020344 JC_DB_DB2 JC_DB Clone_DR full 02/23/2022 04/04/2022 04/04/2022 disk 1645592431 Clone_DR 997 KB MNBDD3302P.corpads.local\n"
+ "rsuedw01.corpads.local 1020344 JC_DB_DB2 full 02/23/2022 04/04/2022 03/30/2022 disk 1645592431 997 KB JCBDD1300P.corpads.local\n"
+ "rsuedw03.corpads.local 12608 MN_UNIX_NP_7_Days MN_DB Clone_DR full 02/23/2022 04/21/2022 04/21/2022 disk 1645592432 Clone_DR 13 KB JCBDD1300P.corpads.local\n";
final String subst = "$1";
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