Tuco Tuco - 1 year ago 86
Java Question

Regular Expression to obtain inner text

I want to obtain the highlighted part from the following text:

Linux version 3.10.49-g5796782 (d00903065@ubuntu)

I've been trying with Pattern and Matcher from the Java library but haven't been able to succeed. Thanks!


Here's my code, I've tried some of the answers but for some reaon it won't have any matches:

String s = "Linux version 3.10.49-g5796782 (d00903065@ubuntu)";
Pattern pattern = Pattern.compile("'^\\D+([-.\\w]+)'");
Matcher matcher = pattern.matcher(s);
if (matcher.find()) {
s = matcher.group(1);
} else {
s = "no match";

Answer Source

Have you tried something like this?


Here's a working example.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download