title: Want to check if a string contains the -
body: <p>I am having some trouble figuring out how to check if the line contains a dash (<code>-</code>) and then capturing a part of it.</p>
  
  <p>Here is an example of strings that I can have as input:</p>
  
  <pre><code>abc,xyz,ijk-a,opq
  
  abc,xyz,ijk,opq
  </code></pre>
  
  <p>I want to extract the part before the dash, if it's present, namely <code>ijk</code>.
  If there is no dash, I just want <code>ijk</code> (as shown in the second string).</p>
  
  <p>The following regex expression uses if condition with lookahead assertion and does the job but always generates one empty group as shown here <a href="http://regex101.com/r/nB8dQ7" rel="nofollow">Regex code here</a>.
  I would like to have only one capturing group returning <code>ijk</code>.</p>
  
  <p>I thought that the regex if condition would only return the group of the if or else condition and not both.</p>
  
  <pre><code>.*,(?(?=.*?-.*?)(.*?)-.*?|(.*?)),
  </code></pre>
  
  <p>Thanks</p>