import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?mi)((?:password=|user=)[^\\n]*$|\\<property key=\\\"variableNames\\\"\\/\\>\\n|\\<property key=\\\"variableValues\\\"\\/\\>\\n)";
final String string = "<maplayer simplifyAlgorithm=\"0\" minimumScale=\"0\" maximumScale=\"2500\" simplifyDrawingHints=\"0\" readOnly=\"0\" minLabelScale=\"0\" maxLabelScale=\"1e+08\" simplifyDrawingTol=\"1\" geometry=\"Point\" simplifyMaxScale=\"1\" type=\"vector\" hasScaleBasedVisibilityFlag=\"1\" simplifyLocal=\"1\" scaleBasedLabelVisibilityFlag=\"0\">\n"
+ " <id></id>\n"
+ " <datasource>port=1521 user=test_user password=test_passwd</datasource>\n"
+ " <keywordList>\n"
+ " <value></value>\n"
+ " </keywordList>\n"
+ " <featformsuppress>0</featformsuppress>\n"
+ " <editorlayout>generatedlayout</editorlayout>\n"
+ " <widgets/>\n"
+ " <conditionalstyles>\n"
+ " <rowstyles/>\n"
+ " <fieldstyles/>\n"
+ " </conditionalstyles>\n"
+ " </maplayer>\n"
+ " </projectlayers>\n"
+ " <properties>\n"
+ " <Variables>\n"
+ " <variableNames type=\"QStringList\">\n"
+ " <value>paswd</value>\n"
+ " <value>user</value>\n"
+ " </variableNames>\n"
+ " <variableValues type=\"QStringList\">\n"
+ " <value>5zdgf</value>\n"
+ " <value>dgdgdgfdg</value>\n"
+ " </variableValues>\n"
+ " </Variables>\n"
+ " <customproperties>\n"
+ " <property key=\"labeling/textColorR\" value=\"0\"/>\n"
+ " <property key=\"labeling/textTransp\" value=\"0\"/>\n"
+ " <property key=\"labeling/upsidedownLabels\" value=\"0\"/>\n"
+ " <property key=\"labeling/useSubstitutions\" value=\"false\"/>\n"
+ " <property key=\"labeling/wrapChar\" value=\"\"/>\n"
+ " <property key=\"labeling/xOffset\" value=\"0\"/>\n"
+ " <property key=\"labeling/yOffset\" value=\"0\"/>\n"
+ " <property key=\"labeling/zIndex\" value=\"0\"/>\n"
+ " <property key=\"variableNames\"/>\n"
+ " <property key=\"variableValues\"/>\n"
+ " </customproperties>";
final String subst = "";
final Pattern pattern = Pattern.compile(regex);
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