import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^Cisco Catalyst.*AC Power Supply$";
final String string = "Cisco Catalyst 9500 Series Chassis\n"
+ "Cisco Catalyst 9500 Series Power Supply Bay Module Container\n"
+ "Cisco Catalyst 9500 Series Power Supply Bay Module Container\n"
+ "Cisco Catalyst 9500 Series Fan Tray Bay Module Container\n"
+ "Cisco Catalyst 9500 Series 650W AC Power Supply\n"
+ "Cisco Catalyst 9500 Series Power Supply\n"
+ "Cisco Catalyst 9500 Series Fan\n"
+ "Cisco Catalyst 9500 Series 650W AC Power Supply\n"
+ "Cisco Catalyst 9500 Series Power Supply\n"
+ "Cisco Catalyst 9500 Series Fan\n"
+ "Cisco Catalyst 9500 Series Fan Tray\n"
+ "Cisco Catalyst 9500 Series Fan Tray\n"
+ "Cisco Catalyst 9500 Series Fan\n"
+ "Cisco Catalyst 9500 Series Fan\n"
+ "Cisco Catalyst 9500 Series Fan\n"
+ "Cisco Catalyst 9500 Series Fan\n"
+ "Cisco Catalyst 9500 Series Fan\n"
+ "Cisco Catalyst 9500 Series Fan\n"
+ "Cisco Catalyst 9500 Series Fan\n"
+ "Cisco Catalyst 9500 Series Fan\n"
+ "Cisco Catalyst 9500 Series Router\n"
+ "PSOC-MB_0: VOU\n"
+ "PSOC-MB_1: VOU\n"
+ "PSOC-MB_2: VOU\n"
+ "PSOC-MB_3: VOU\n"
+ "PSOC-MB_4: VOU\n"
+ "PSOC-MB_5: VOU\n"
+ "PSOC-MB_7: VOU\n"
+ "PSOC-MB_8: VOU\n"
+ "PSOC-MB_9: VOU\n"
+ "PSOC-MB_10: VO\n"
+ "3570MB1_0: VOU\n"
+ "3570MB2_0: VOU\n"
+ "3570MB3_0: VOU\n"
+ "35215MB1_0: VO\n"
+ "35215MB2_0: VO\n"
+ "Temp: Outlet_A\n"
+ "Temp: Outlet_B\n"
+ "Temp: Inlet_A\n"
+ "Temp: Inlet_B\n"
+ "Temp: UADP_0_0\n"
+ "Temp: UADP_0_1\n"
+ "Temp: UADP_0_2\n"
+ "Temp: UADP_0_3\n"
+ "Temp: UADP_0_4\n"
+ "Temp: UADP_0_5\n"
+ "Temp: UADP_0_6\n"
+ "Temp: UADP_0_7\n"
+ "Temp: UADP_0_8\n"
+ "PSOC-DB_1: VOU\n"
+ "PSOC-DB_2: VOU\n"
+ "PSOC-DB_4: VOU\n"
+ "PSOC-DB_5: VOU\n"
+ "PSOC-DB_7: VOU\n"
+ "PSOC-DB_8: VOU\n"
+ "PSOC-DB_11: VO\n"
+ "3570DB1_0: VOU\n"
+ "3570DB2_0: VOU\n"
+ "3570DB3_0: VOU\n"
+ "Temp: Coretemp\n"
+ "Temp: OutletDB\n"
+ "Intel CPU x86-64\n"
+ "USB Port\n"
+ "TwentyFiveGigE1/0/1 Container\n"
+ "TwentyFiveGigE1/0/2 Container\n"
+ "TwentyFiveGigE1/0/3 Container\n"
+ "TwentyFiveGigE1/0/4 Container\n"
+ "TwentyFiveGigE1/0/5 Container\n"
+ "TwentyFiveGigE1/0/6 Container\n"
+ "TwentyFiveGigE1/0/7 Container\n"
+ "TwentyFiveGigE1/0/8 Container\n"
+ "TwentyFiveGigE1/0/9 Container\n"
+ "TwentyFiveGigE1/0/10 Container\n"
+ "TwentyFiveGigE1/0/11 Container\n"
+ "TwentyFiveGigE1/0/12 Container\n"
+ "TwentyFiveGigE1/0/13 Container\n"
+ "TwentyFiveGigE1/0/14 Container\n"
+ "TwentyFiveGigE1/0/15 Container\n"
+ "TwentyFiveGigE1/0/16 Container\n"
+ "TwentyFiveGigE1/0/17 Container\n"
+ "TwentyFiveGigE1/0/18 Container\n"
+ "TwentyFiveGigE1/0/19 Container\n"
+ "TwentyFiveGigE1/0/20 Container\n"
+ "TwentyFiveGigE1/0/21 Container\n"
+ "TwentyFiveGigE1/0/22 Container\n"
+ "TwentyFiveGigE1/0/23 Container\n"
+ "TwentyFiveGigE1/0/24 Container\n"
+ "HundredGigE1/0/25 Container\n"
+ "HundredGigE1/0/26 Container\n"
+ "HundredGigE1/0/27 Container\n"
+ "HundredGigE1/0/28 Container\n"
+ "SFP+ 10GBASE-SR\n"
+ "Twe1/0/1 Module Temperature Sensor\n"
+ "Twe1/0/1 Supply Voltage Sensor\n"
+ "Twe1/0/1 Bias Current Sensor\n"
+ "Twe1/0/1 Transmit Power Sensor\n"
+ "Twe1/0/1 Receive Power Sensor\n"
+ "GE T\n"
+ "GE T\n"
+ "SFP+ 10GBASE-SR";
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