import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "2(?:12|4[1-9]|5[1-9]|6[0-9]|7[0-8]|8[1-35-8]|9[1-5]|3[45789])|4(?:1[246]|2[46])";
final String string = "248, 281, 282, 283, 235, 247, 278, 243, 244, 245, 246, 273, 278, 235, 285, 286, 288, \n"
+ "241, 242, 243, 245, 249, 258, 287, 212, 259, 268, 269, 237, 235, 238, 246, 247, 251, \n"
+ "252, 253, 271, 273, 274, 275, 212, 234, 239, 287, 291, 292, 295, 255, 256, 257, 293, \n"
+ "294, 276, 277, 271, 272, 212, 251, 253, 254, 261, 262, 263, 264, 265, 266, 267, 271, \n"
+ "275, 260, 270, 412, 414, 424, 416, 426";
final String subst = "";
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