import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "((?<A>\\s(greater|less|earlier)\\sth[a|e]n)((?<B>\\sor equal)[s]?)?(\\sto)?\\s)(?<V>[^\\s]+)?";
final String string = "Check if the version of xpsviewer.exe is greater than or equal to 3.0.6920.7000\n"
+ "Check if OpenSSL 1.1.0 version is greater than or equal 1.1.0 and less than 1.1.0e\n"
+ "Check if Oracle VM VirtualBox version is greater than or equals to 3.2.0\n"
+ "Version of VLC Media Player less than or equal to 2.0.4\n"
+ "Check if Java SE Development Kit 1.6 version is less than or equal 6.0.1710\n"
+ "Version of VLC Media Player greater than or equal to 0.5.0 and less than or equal to 0.9.5\n"
+ "the version of cryptdlg.dll is less then 5.0.1558.6072\n"
+ "Check if the version of Microsoft.sqlserver.chainer.infrastructure.dll is less than 14.0.2000.63 and greater than 14.0.0\n"
+ "Check if OpenSSL version is less than or equals to 0.9.8.24 in VisualSVN Server\n"
+ "Determine if the version of JavaFX is less than 2.2.46 (JRE 1.7.0:update_6 and later)\n"
+ "Mozilla Firefox ESR version is less than 24.1 and greater than or equal to 24.x\n"
+ "Check if SQL Server instances with version less than 2009.100.4000.0 and greater than or equal 2009.100.2500.0\n"
+ "Excel 2000 SP3 or greater is installed\n"
+ "Mozilla Firefox version 3.5.x to 3.5.1 or less than 3.0.14\n"
+ "Check if ssleay32.dll 1.0.1 version is greater than or equal 1.0.1 and less than 1.0.1u on ProgramFilesDir (x86)\n"
+ "Check if SQL Server instances with version greater than or equal 2007.100.6000.0 and less than 2009.100.1600.1 exist\n"
+ "Check if outlook.exe version is greater than or equal to 16.0.8201.0000 and less than 16.0.8201.2213 (MSO 2016 Version 1705)\n"
+ "firefox DPKG is earlier than 0:32.0+build1-0ubuntu0.12.04.1\n"
+ "openjdk-7-jre-headless DPKG is earlier than 0:7u65-2.5.1-4ubuntu1~0.14.04.1\n"
+ "kvm DPKG is earlier than 84+dfsg-0ubuntu16+0.12.3+noroms+0ubuntu9.4\n"
+ "Check if the version of ssleay32.dll 0.9.1c before 0.9.8y ProgramFilesDir x86\n"
+ "Check if the version of OpenSSL 0.9.1c before 0.9.8s (32_bit)\n"
+ "Version of Wireshark is 1.4.x before 1.4.15, 1.6.x before 1.6.10, or 1.8.x before 1.8.2\n"
+ "Version of Wireshark is 1.8.x before 1.8.10 or 1.10.x before 1.10.2\n"
+ "Check if the version of PHP is less than 5.2.15 or 5.3.x before 5.3.4\n\n";
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