title: Regular Expression to find multiple email addresses in a file in java
body: <p>I have a file which have a series of multiple email addresses. I need to separate emails from it using Regex in java. I have taken a sample string and tried like below.</p>
  
  <pre><code>import java.util.HashSet;
  import java.util.Set;
  import java.io.*;
  import java.util.*;
  import java.util.regex.*;
  
  
  
  public class Email2 {
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          String content = "s.lokesh1729@gmail.com,lokesh.harshitha1729@gmail.com";
          Pattern p = Pattern.compile("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
                  + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
          Matcher m = p.matcher(content);
          if(m.find())
          {
              System.out.println(m.group(1));
              System.out.println(m.group(2));
          }
      }
  
  }
  </code></pre>
  
  <p>The above code doesn't returns anything, but if I changed content to containing only one email address, it returns. I know that I can split it with the comma or any other special character, but I want to do it with Regular Expressions?</p>