jeudi 12 avril 2018

Regex pattern matching with multiple match in java

When I try to use online regex tool https://regex101.com/r/hU6vM1/1 it gives me correct result but when i use it in code I just get the first match only. Here is my code

   public String getDomain(String email) {
    Pattern pattern = Pattern.compile("([^.@]+)\\.");
    Matcher matcher = pattern.matcher(email);

    if (matcher.find()) {
        System.out.println("Matcher count:=" + matcher.groupCount());
        System.out.println("Match is=" + matcher.group());
    } 

But i am getting only one count and one value. Like for email: user22@email1.email.com Output i got is email1

Please can someone help me with it. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire