import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "<bean id=.*processName\"\\s*value=\"([a-zA-Z0-9\\.]*).*processVersion\"\\s*value=\"([0-9\\.]*)\".*<\\/bean>";
final String string = "<bean id=\"AuthenticationServicePDCAdapter\" class=\"br.com.bradesco.web.crur.service.data.pdc.authenticationservice.AuthenticationServicePDCAdapterImpl\" parent=\"PDCAdapterAbstract\" abstract=\"false\" singleton=\"true\" lazy-init=\"true\" autowire=\"default\" dependency-check=\"default\"> <property name=\"group\" value=\"INTRANET\"/> <property name=\"description\" value=\"Insert description here\"/> <property name=\"processName\" value=\"intranet.framework.logon\"/> <property name=\"processVersion\" value=\"1.0.9\"/> <property name=\"adapterPackage\" value=\"br.com.bradesco.web.crur.service.data.pdc\"/> <property name=\"processProduct\" value=\"Intranet\"/> <property name=\"isLoginRequired\" value=\"false\"/> <property name=\"baseClassRequestName\" value=\"LogonRequest\"/> <property name=\"baseClassResponseName\" value=\"LogonResponse\"/> <property name=\"factoryId\" value=\"factoryAdapter\"/> <property name=\"factoryPackage\" value=\"br.com.bradesco.web.crur.service.data.pdc\"/> <property name=\"factoryClassName\" value=\"FactoryAdapter\"/> <property name=\"isNewAwbFrameworkVersion\" value=\"true\"/> <property name=\"pdcConnector\" ref=\"${pdc.connector}\"/> </bean> \n";
final String subst = "$1-$2";
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