Reputation: 641
I've implemented the test regex below in Java but I can't see any matches. I'm new to regex but it looks like it should find a match. Anything I am doing wrong here?
public static void main(String[] args) {
// TODO Auto-generated method stub
String process= "SSHD is running: PID:12506, Wrapper:STARTED, Java:STOPPPED";
Pattern patternFileToScan = Pattern.compile("SSHD is running: PID:[d]{1,5}, Wrapper:STARTED, Java:STARTED");
Matcher matcherFileToScan = patternFileToScan.matcher(process);
System.out.println("TEST");
if(matcherFileToScan.matches()) {
System.out.println(matcherFileToScan.group());
}
}
Upvotes: 1
Views: 130
Reputation: 36304
Change PID:[d]{1,5}
to PID:\\d{1,5}
.
[d]{1,5}
will try to match the character d
not numbers.
Upvotes: 6