2

I have this regex that works OK in perl. However in java I am getting an exception when running this code.

    String procTime="125-23:02:01";
    String pattern = "([0-9]+)-([0-9]+):([0-9]+):([0-9]+).*";
    Pattern r = Pattern.compile(pattern);
    Matcher mt = r.matcher(procTime);
    String a = mt.group(0); // throws exception not fnd
    String d = mt.group(1);

1 Answer 1

5

You're not calling Matcher#find or Matcher#matches command in your code. Following will work:

String procTime="125-23:02:01";
String pattern = "([0-9]+)-([0-9]+):([0-9]+):([0-9]+).*";
Pattern r = Pattern.compile(pattern);
Matcher mt = r.matcher(procTime);
if (mt.find()) {
   String a = mt.group(0); // should work now
   String d = mt.group(1);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank You. (comment must be at least 15 char in length)

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.