import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^[A-Za-z]-.*$|^[A-Za-z]\\s.*$";
final String string = "CASE\n"
+ "regexp_replace (od_proposed,'^[A-Za-z]-.*$','^[A-Za-z]-\\d$')\n"
+ "regexp_replace (od,'^[A-Za-z]\\s.*$','^[A-Za-z]')\n\n\n\n"
+ "A-1 - AIRPLANE\n"
+ "A-2 - AIRPLANE\n"
+ "A-3 - AIRPLANE\n"
+ "A-4 - AIRPLANE\n"
+ "A-5 - AIRPLANE\n"
+ "B - BOARD ROOM\n"
+ "E - EMERGENCY: FIRST ROOM\n"
+ "F-1 - FIRST \n"
+ "F-2 - FIRST \n"
+ "H-1 - HOUSING\n"
+ "H-2 - HOUSING\n"
+ "H-3 - HOUSING\n"
+ "H-4 - HOUSING\n"
+ "I-1 - INITIAL\n"
+ "I-2 - INITIAL\n"
+ "I-3 - INITIAL\n"
+ "I-4 - INITIAL\n"
+ "M - MASTER\n"
+ "R-1 - REASON\n"
+ "R-2 - REASON\n"
+ "R-3 - REASON\n"
+ "S-1 - SHORTCUT: TO CAFE\n"
+ "S-2 - SHORTCUT: TO CAFE\n"
+ "U - UTILITY";
final Pattern pattern = Pattern.compile(regex);
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