import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main
{
static void processString
(String line
) {
System.
out.
println("Processing: " + line
); Pattern p = Pattern.compile("\\G(\\w+)=(\\w+);");
Matcher m = p.matcher(line);
int lastMatchPos = 0;
while (m.find()) {
System.
out.
println(" " + m.
group(1) + " - " + m.
group(2)); lastMatchPos = m.end();
}
if (lastMatchPos != line.length())
System.
out.
println(" Invalid string!"); }
public static void main
(String[] args
) {
processString("name1=gil;name2=orit;");
processString("name1=gil;name2=orit;a");
processString("name1=gil;;name2=orit;");
processString(";name1=gil;name2=orit;");
processString("name1=gil;=name2=orit;");
}
}
aW1wb3J0IGphdmEudXRpbC5yZWdleC5NYXRjaGVyOwppbXBvcnQgamF2YS51dGlsLnJlZ2V4LlBhdHRlcm47CgpwdWJsaWMgY2xhc3MgTWFpbgp7CiAgIHN0YXRpYyB2b2lkIHByb2Nlc3NTdHJpbmcoU3RyaW5nIGxpbmUpCiAgIHsKICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJQcm9jZXNzaW5nOiAiICsgbGluZSk7CiAgICAgIFBhdHRlcm4gcCA9IFBhdHRlcm4uY29tcGlsZSgiXFxHKFxcdyspPShcXHcrKTsiKTsKICAgICAgTWF0Y2hlciBtID0gcC5tYXRjaGVyKGxpbmUpOwogICAgICBpbnQgbGFzdE1hdGNoUG9zID0gMDsKICAgICAgd2hpbGUgKG0uZmluZCgpKSB7CiAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiICAiICsgbS5ncm91cCgxKSArICIgLSAiICsgbS5ncm91cCgyKSk7CiAgICAgICAgIGxhc3RNYXRjaFBvcyA9IG0uZW5kKCk7CiAgICAgIH0KICAgICAgaWYgKGxhc3RNYXRjaFBvcyAhPSBsaW5lLmxlbmd0aCgpKQogICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIiAgSW52YWxpZCBzdHJpbmchIik7CiAgIH0KICAgCiAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ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