import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "iPhone [6-7]";
final String string = "iPhone 7 Plus\n"
+ "iPad Pro 12.9 2015 iOS15.5 beta 4\n"
+ "iPhone 11 Pro iOS15.5 beta4\n"
+ "iPad Pro 10.5 2017\n"
+ "iPad 9.7 2018 iOS15.5 beta4\n"
+ "iPhone X \n"
+ "iPhone 11 Pro Max\n"
+ "iPad Pro 10.5 2017\n"
+ "iPad mini 3\n"
+ "iPhone X\n"
+ "iPad Pro 12.9 2021\n"
+ "iPhone 13\n"
+ "iPhone 11\n"
+ "iPhone 12 mini\n"
+ "iPad Pro 12.9 2018\n"
+ "iPad Pro 11 2018\n"
+ "iPhone 12\n"
+ "iPhone X iOS15.5 beta4\n"
+ "iPad Air 2\n"
+ "iPhone 8\n"
+ "iPhone 6\n"
+ "iPhone XS Max\n"
+ "iPad mini 4\n"
+ "iPad Air 3 (2019)\n"
+ "iPhone SE 2020\n"
+ "iPhone 11 Pro\n"
+ "iPhone 12 Pro\n"
+ "iPad Mini 2019\n"
+ "iPad 9.7 2018\n"
+ "iPad 10.2 2020\n"
+ "iPhone SE\n"
+ "iPad Air 2\n"
+ "iPad Air 2022 5th Gen\n"
+ "iPad Air 2020\n"
+ "iPad Air 2\n"
+ "iPad Pro 11 2021\n"
+ "iPhone SE 2020\n"
+ "iPhone 6 Plus\n"
+ "iPad Pro 11 2020\n"
+ "iPad 10.2 2020\n"
+ "iPad Pro 10.5 2017\n"
+ "iPad 10.2\n"
+ "iPhone XR\n"
+ "iPad Pro 12.9 2015\n"
+ "iPad Pro\n"
+ "iPad Air 2\n"
+ "iPhone 7\n"
+ "iPad Mini 2021 6th Gen\n"
+ "iPad Air 2020\n"
+ "iPhone 8 Plus\n"
+ "iPhone 11\n"
+ "iPad 9.7 2017 5th Gen\n"
+ "iPhone XS\n"
+ "iPad Pro 12.9 2020\n"
+ "iPhone 6S\n"
+ "iPad Air\n"
+ "iPhone XS Max\n"
+ "iPhone SE 2020\n"
+ "iPhone_11_Pro\n"
+ "iPhone 5S\n"
+ "iPhone 8\n"
+ "iPhone 7 Plus\n"
+ "iPod Touch 6\n"
+ "iPad Pro 9.7\n"
+ "iPhone 12 mini iOS15.5 beta4\n"
+ "iPhone X\n"
+ "iPhone 8\n"
+ "iPhone 6\n"
+ "iPhone X\n"
+ "iPhone 13 Pro Max\n"
+ "iPhone 12 Pro Max\n"
+ "iPad Air 2 iOS15.5 beta4\n"
+ "iPhone 6\n"
+ "iPad mini 4\n"
+ "iPad Pro 11 2018\n"
+ "iPad Pro 12.9 2015\n"
+ "iPhone XR\n"
+ "iPhone XS\n"
+ "iPhone XR\n"
+ "iPhone 7\n"
+ "iPad Pro 12.9 2017\n"
+ "iPhone 8\n"
+ "iPhone 6S\n"
+ "iPad Pro 12.9 2017\n"
+ "iPad Pro 12.9\n"
+ "iPhone X \n"
+ "iPhone 8 Plus\n"
+ "iPad Air 3 (2019)\n"
+ "iPhone 8\n"
+ "iPhone 12 Pro Max\n"
+ "iPad Pro 12.9 2015\n"
+ "iPad mini 4\n"
+ "iPhone 13 mini\n"
+ "iPad Air 2\n"
+ "iPhone 13 Pro\n"
+ "iPhone 7\n"
+ "iPhone XS\n"
+ "iPad 10.2 2021 9th Gen\n"
+ "iPhone SE 2020\n"
+ "iPod Touch 7\n"
+ "iPad Air 2\n"
+ "iPhone 7 Plus\n"
+ "iPhone SE 2022\n"
+ "iPhone 6S Plus\n"
+ "iPhone 12";
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