import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?i)\\b(Devices|Community String)\\b\\s*-\\s*([\\w,\\/]+)";
final String string = "1. What is being changed?\n"
+ "Add in Solarwinds monitoring the router and switch of the new Store:\n\n"
+ "Devices - MCHLS5178,sw517801,sr517800,sr517801,sr517802,MCHLS5184,sw518401,sr518400,sr518401,sr518402\n"
+ "Community String - N/A\n\n\n"
+ " \n\n"
+ "2. Where it is being changed?\n"
+ "Solarwinds monitoring (10.3.4.7)\n\n"
+ " \n\n"
+ "3. Why it is being changed?\n"
+ "To monitor the router and switch of the store 5178,5184\n\n"
+ " \n\n"
+ "4. What is the Business Impact of the Change?\n"
+ "No business impact during implementation.\n\n"
+ " \n\n"
+ "5. Who will be doing the change? \n"
+ "Network team\n\n"
+ " \n\n"
+ "6. When is the change happening?\n"
+ "2020-01-26 01:00:00\n\n"
+ " \n\n"
+ "7. Who will be testing the change after implementation?\n"
+ "Network team";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
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