/* package whatever; // don't place package name! */
import java.util.*;
import java.util.regex.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
Pattern p = Pattern.compile("^(dog)(.+(cat))?");
for (String s
: new String[] {"dog, cat",
"dog, dog, cat",
"dog, dog, dog",
"dog, dog, cat, blah"}) { Matcher m = p.matcher(s);
if (m.find()) {
System.
out.
println(m.
group(1)+" "+m.
group(3)); }
}
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS51dGlsLnJlZ2V4Lio7CmltcG9ydCBqYXZhLmxhbmcuKjsKaW1wb3J0IGphdmEuaW8uKjsKCi8qIE5hbWUgb2YgdGhlIGNsYXNzIGhhcyB0byBiZSAiTWFpbiIgb25seSBpZiB0aGUgY2xhc3MgaXMgcHVibGljLiAqLwpjbGFzcyBJZGVvbmUKewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uCgl7CgkJUGF0dGVybiBwID0gUGF0dGVybi5jb21waWxlKCJeKGRvZykoLisoY2F0KSk/Iik7CgkJZm9yIChTdHJpbmcgcyA6IG5ldyBTdHJpbmdbXSB7ImRvZywgY2F0IiwgImRvZywgZG9nLCBjYXQiLCAiZG9nLCBkb2csIGRvZyIsICJkb2csIGRvZywgY2F0LCBibGFoIn0pIHsKCQkJTWF0Y2hlciBtID0gcC5tYXRjaGVyKHMpOwoJCQlpZiAobS5maW5kKCkpIHsKCQkJCVN5c3RlbS5vdXQucHJpbnRsbihtLmdyb3VwKDEpKyIgIittLmdyb3VwKDMpKTsKCQkJfQoJCX0KCX0KfQ==