title: regex for if condition in java
body: <p>so i have this problem..
  POLL followed by a combination of 10 As, Ds, or Ms (agree, disagree, maybe), follwed by a yes or no.  If the answer is a no, there must be a reason that should follow.</p>
  
  <p>Capture the ff:</p>
  
  <ul>
  <li>The A, D, M answers</li>
  <li>The yes/no answer</li>
  <li>[The reason that follows a no]</li>
  </ul>
  
  <p>//case insensitive</p>
  
  <p>i came up to this regex </p>
  
  <pre><code> POLL\s+([ADM]{10})\s+(yes|no\s+([a-z. ]+))
  </code></pre>
  
  <p>The string is: <code>POLL admaaadddm no no comment</code></p>
  
  <p>The output is:</p>
  
  <pre><code>combination --&gt; admaaadddm
  yes or no --&gt; no no comment  //this should be fix, it must capture no only
  reason --&gt; no comment
  </code></pre>
  
  <p>my code:</p>
  
  <pre><code>    String message = "POLL admaaadddm no no comment";
  
      Pattern pattern = Pattern.compile("POLL\\s+([ADM]{10})\\s+(yes|no\\s+([a-z. ]+))"
              ,Pattern.CASE_INSENSITIVE);
  
  
      Matcher m = pattern.matcher(message);
  
      try
      {
          if (m.matches())
          {
  
              String combination = m.group(1);
              String yesno = m.group(2);
              String reason = m.group(3);
  
              System.out.println(combination);
              System.out.println(yesno);
              System.out.println(reason);
  
          }
      }
      catch (NullPointerException e)
      {
      }
  </code></pre>