1

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());
      }

}

1 Answer 1

6

Change PID:[d]{1,5} to PID:\\d{1,5}.

[d]{1,5} will try to match the character d not numbers.

Sign up to request clarification or add additional context in comments.

2 Comments

@TheLostMind, you don't need to have char class.
@AvinashRaj - Can't deny that now .. can I? :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.