Although you should be careful when using regex over xml ... this will be done on one line:
String filename = input.replaceAll("(?s).*<name>(.*)</name>.*<ruleId>(.*)</ruleId>.*<ruleVersion>(.*)</ruleVersion>.*", "$1_$2_$3.xml");
Important (?s)
Here check this line which you can run:
public static void main(String[] args) throws Exception { String input = "<name>remove use case</name>\n <ruleId>2161</ruleId>\n <ruleVersion>0.0.1</ruleVersion>\n <ruleStatus>New</ruleStatus>\n <nuggetId>489505737</nuggetId>\n <icVersionId>50449</icVersionId>\n <rlVersion>1.0</rlVersion>\n <modelVersion>1.0</modelVersion>\n <attributes>\n <attribute>\n <attributeName/>\n <value/>\n </attribute>\n </attributes>\n <notes></notes>"; String filename = input.replaceAll("(?s).*<name>(.*)</name>.*<ruleId>(.*)</ruleId>.*<ruleVersion>(.*)</ruleVersion>.*", "$1_$2_$3.xml"); System.out.println(filename); }
Output:
remove use case_2161_0.0.1.xml
source share