Well, you could search for a similar question.;
regexp to match java package name
I modified the regex from the top answer to suit your case. I replace the ^…$
(line start/end) portion with \b
(word boundaries).
import java.util.regex.*;
public class RegexTest {
public static final String PACKAGE_PATTERN = "\\b[a-z][a-z0-9_]*(\\.[a-z0-9_]+)+[0-9a-z_]\\b";
public static void main(String[] args) {
String s = "id= com.mycomp.war.tasks.JmxMetricsTask I run/id-geLh3hM1-1_2 [Svc--DAG]";
Pattern p = Pattern.compile(PACKAGE_PATTERN, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(s);
if (m.find()) {
System.out.println(m.group()); // com.mycomp.war.tasks.JmxMetricsTask
}
}
}
Here's a live example using Regex 101: /\b[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]\b/ig
https://regex101.com/r/RwJtLK/2
You could also just split by whitespace characters and grab the second token.
public class RegexTest {
public static void main(String[] args) {
String s = "id= com.mycomp.war.tasks.JmxMetricsTask I run/id-geLh3hM1-1_2 [Svc--DAG]";
String[] tokens = s.split("\\s+");
System.out.println(tokens[1]); // com.mycomp.war.tasks
}
}