Couple<String> (@NotNull String authorString) { //special characters should be retained for properly filtering by username. For Mercurial "a.b" username is not equal to "a b" // Vasya Pupkin <vasya.pupkin@jetbrains.com> -> Vasya Pupkin , vasya.pupkin@jetbrains.com int startEmailIndex = authorString.indexOf('<'); int startDomainIndex = authorString.indexOf('@'); int endEmailIndex = authorString.indexOf('>'); String userName; String email; if (0 < startEmailIndex && startEmailIndex < startDomainIndex && startDomainIndex < endEmailIndex) { email = authorString.substring(startEmailIndex + 1, endEmailIndex); userName = authorString.substring(0, startEmailIndex).trim(); } // vasya.pupkin@email.com || <vasya.pupkin@email.com> else if (!authorString.contains(" ") && startDomainIndex > 0) { //simple e-mail check. john@localhost userName = ""; if (startEmailIndex >= 0 && startDomainIndex > startEmailIndex && startDomainIndex < endEmailIndex) { email = authorString.substring(startEmailIndex + 1, endEmailIndex).trim(); } else { email = authorString; } } else { userName = authorString.trim(); email = ""; } return Couple.of(userName, email); }