I am new to regex in java..
i have a string "2:05pm - 2:40 pm" i need to get "2:05pm" and "2:40 pm" out from the single string using regex
I am using the follow regex expression, but I am getting wrong somewhere, don't know where
public static void main(String args[])
{
Pattern MY_PATTERN = Pattern.compile("(\\d+)[:](\\d+)(\\s*)((am?)|(pm?))");
String s = "2:05pm - 2:40pm";
Matcher m = MY_PATTERN.matcher(s);
int i=1;
while (m.find()) {
System.out.println(m.group(i++));
}
}