find the unique e-mail addresses vis regex - Java Regular Expressions

Java examples for Regular Expressions:Email

Description

find the unique e-mail addresses vis regex

Demo Code



import java.io.IOException;
import java.util.Iterator;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{
  public static void main(String args[]) throws IOException {

    TreeSet<String> ts = new <String>TreeSet();

    String str = "abc@email.com";
    Pattern p = Pattern.compile("[A-Za-z_.]{1,}@[a-z.]*[a-z]{1,3}");
    Matcher m = p.matcher(str);//from  ww  w. ja v a  2  s .co m

    if (m.find()) {
      ts.add(m.group());
    }

    Iterator<String> it = ts.iterator();
    while (it.hasNext()) {
      System.out.print(it.next());
      if (it.hasNext())
        System.out.print(";");
      else
        System.out.println("");
    }
  }
}

Related Tutorials