import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^([\\w\\.]+)\\s*\\d[\\d\\.\\-]*\\w*";
final String string = "3rosCore 2.0.9\n"
+ "3rosCore 2.0.9-rc\n"
+ "3rosCore 2.0.8\n"
+ "3rosCore 2.0.8-rc\n"
+ "3rosCore 2.0.7\n"
+ "3rosCore 2.0.6\n"
+ "3rosCore 2.0.5\n"
+ "3rosCore 2.0.5-rc\n"
+ "3rosCore 2.0.4-rc\n"
+ "3rosCore 1.0.7\n"
+ "3rosCore 1.0.6\n"
+ "3rosCore 1.0.5\n"
+ "3rosCore 1.0.4\n"
+ "3rosCore 1.0.3\n"
+ "3rosCore 1.0.2\n"
+ "3rosCore 1.0.1\n"
+ "3rosWeb 2.0.0-rc\n"
+ "3rosWeb 1.0.2-rc\n"
+ "3rosWeb 1.0.1\n"
+ "3rosWeb 1.0.0\n"
+ "3rosWebApi 2.0.0\n"
+ "3rosWebApi 1.0.0\n"
+ "Actsis.ECharts.Standard 8.0.1695-beta\n"
+ "Actsis.ECharts.Standard 8.0.1691-beta\n"
+ "Actsis.ECharts.Standard 8.0.1689-beta";
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