title: Regex to match 2 or none?
body: <p>I have this regex to identify if the line contains two underscores:</p>
  
  <pre><code>\s*_{2}(\w+)
  </code></pre>
  
  <p>Any space, two underscores and then a word.  It turns out, I need to know also for no underscore at all, so I have:</p>
  
  <pre><code>\s*(\w+)
  </code></pre>
  
  <p>Optional spaces followed by a word.  Then I get the group 1 which is my word. So far so good. </p>
  
  <p>The problem is the action taken when two underscores are used, is almost identical to the code when no underscore are use ( except that I raise a flag ) </p>
  
  <pre><code>if( s =~ uderscore ) { 
     takeGroup( 1 )
     yada yada 
     flag = true
  } else if( s =~ noUnderscore { 
    takeGroup( 1 ) 
    yada yada 
     flag = false 
  }
  </code></pre>
  
  <p>I think there must be a better way instead of duplicating the whole regexp and test with and with out. </p>