title: Using regex to filter bunch of email addresses in text with some specific conditions
body: <p>I'm experimenting with regex and I'm trying to filter out bunch of email addresses that are embedded in some text source. The filter process will be on two specific conditions:</p>
  
  <ol>
  <li><p>Every email starts with <code>abc</code></p></li>
  <li><p>Regular email patter which includes an <code>@</code> followed by a <code>.</code> and
  ending specifically in <code>com</code></p></li>
  </ol>
  
  <p>Source:</p>
  
  <blockquote>
    <p>sajgvdaskdsdsds<code>abcdefghij@gmail.com</code>sdksdhkshdsdk<code>abcdefghij123@gmail.com</code>wdgjkasdsdad</p>
    
    <p>Pattern1 = "abc[\w\W]<em>[@][\w]</em>\.com</p>
  </blockquote>
  
  <p>code: </p>
  
  <pre><code>public class Test {
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args)
      {
          boolean found = false;
          String source = "sajgvdaskdsdsdsabcdefghij@gmail.comsdksdhkshdsdkabcdefghij123@gmail.comwdgjkasdsdad";
  
  
          String pattern1 = "abc[\\w\\W]*[@][\\w]*\\.com";
  
          Pattern p1 = Pattern.compile(pattern1);
          Matcher m1 = p1.matcher(source);
          System.out.println("Source:\t" + source);
          System.out.println("Exprsn:\t" + m1.pattern());
          while (m1.find())
          {
              found = true;
              System.out.println("Pos: " + m1.start() + "\tFound: " + m1.group());
          }
          System.out.println();
          if(!found)
          {
              System.out.println("Nothing found!");
          }
  
      }
  
  }
  </code></pre>
  
  <p>I'm expecting o/p as: </p>
  
  <blockquote>
    <p>Pos: 15   Found: abcdefghij@gmail.com</p>
    
    <p>Pos: 48   Found: abcdefghij123@gmail.com</p>
  </blockquote>
  
  <p>But getting: </p>
  
  <blockquote>
    <p>Pos: 15   Found:
    abcdefghij@gmail.comsdksdhkshdsdkabcdefghij123@gmail.com</p>
  </blockquote>
  
  <p>If I use this Pattern2: <code>abc[\\w]*[@][\\w]*\\.com</code> then I'm getting the expected o/p. However, the thing is email address can contain non-word characters after <code>abc</code> and before <code>@</code>. (For example: <code>abcd$efghi$@gmail.com</code>).</p>
  
  <p>Hence Pattern2 doesn't work with non-word characters. So, I went with <code>[\\w\\W]*</code> instead of <code>[\\w]*</code>. </p>
  
  <p>I also tried Pattern3: <code>abc[\\w\\W][@][\\w]\\.com[^.]</code> and still doesn't work.</p>
  
  <p>Please help me, where am I doing wrong? </p>