0

Why I've got IllegalStateException with message "No match found" here?
String email = m.group(); produces it while trying to get last group of the string (group = "E1")

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Solution
{
    public static void main(String[] args)
    {
        convert1("Login;Name;Email\nL1;N1;E1");
    }

    public static void convert1(String input)
    {
        Pattern p = Pattern.compile(".+?[;\n$]");
        Matcher m = p.matcher(input);

        while (m.find())
        {
            String login = m.group();
            login = login.substring(0, login.length() - 1);
            m.find();
            String name = m.group();
            name = name.substring(0, name.length() - 1);
            m.find();
            String email = m.group(); // IllegalStateException: No match found
            email = email.substring(0, email.length() - 1);
        }
    }
}
Denys_newbie
  • 1,140
  • 5
  • 15

0 Answers0