import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^.*added:[\\s\\S]*?(?=^[^+-])";
final String string = "demo, demo-setga, Deployment (apps) has changed:\n"
+ "...\n"
+ "- image: \"imagedemo43\"\n"
+ "+ image: \"imagedemo44\"\n"
+ "...\n"
+ "demo, demo-app1, Deployment (apps) has been removed:\n"
+ "- # Source: /charts/app1/templates/deploy.yaml\n"
+ "- apiVersion: apps/v1\n"
+ "- imagePullSecrets:\n"
+ "- - name: demo-registry\n"
+ "+\n"
+ "demo, demo-app2, Deployment (apps) has changed:\n"
+ "...\n"
+ "- value: 4.2.0\n"
+ "+ value: 4.3.0\n"
+ "...\n"
+ "demo, demo-app4, Deployment (apps) has been added:\n"
+ "-\n"
+ "+ apiVersion: apps/v1\n"
+ "+ kind: Deployment\n"
+ "+ metadata:\n"
+ "+ heritage: Helm\n"
+ "+ imagePullSecrets:\n"
+ "+ - name: demo-registry\n"
+ "demo, demo-app9, Deployment (apps) has changed:\n"
+ "...\n"
+ "- value: 2.2.0\n"
+ "+ value: 4.3.0\n"
+ "...\n"
+ "demo, demo-app5, PodDisruptionBudget (policy) has been added:\n"
+ "-\n"
+ "+ apiVersion: policy/v1beta1\n"
+ "+ kind: PodDisruptionBudget\n"
+ "+ metadata:\n"
+ "+ app: app5\n"
+ "+ release: demo\n"
+ "../helm_var/test/dev/secrets.yaml.dec\n"
+ "demo, demo-app8, PodDisruptionBudget (policy) has been added:\n"
+ "-\n"
+ "+ # Source: test/charts/app5/templates/pdb.yaml\n"
+ "+ apiVersion: policy/v1beta1\n"
+ "+ matchLabels:\n"
+ "+ app: app5\n"
+ "+ release: demo\n"
+ "demo, demo-app9, Deployment (apps) has changed:\n"
+ "...\n"
+ "- value: 4.1.0\n"
+ "+ value: 9.3.0\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