title: Regular expression to select 2 kinds of substrings
body: <p>I have strings like:</p>
  
  <ol>
  <li><code>\n A vs B \n</code></li>
  <li><code>\n C vs D (EF) \n</code></li>
  <li><code>\n GH ( I vs J) \n</code></li>
  </ol>
  
  <p>in a vector called <code>myData</code>.</p>
  
  <p>The following is <code>myData</code>.</p>
  
  <pre><code>c("\n A vs B \n", "\n C vs D (EF) \n", "\n GH ( I vs J)\n")
  </code></pre>
  
  <p>I want to select <code>A vs B</code> from 1, <code>C vs D</code> from 2 and <code>I vs J</code> from 3.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>loc  = regexpr(".*vs.*|\\(.*vs.*\\)",myData,ignore.case=TRUE,perl=T)
  
  end  = loc  + attr(loc,"match.length")-1
  
  substr(myData,loc,end)
  </code></pre>
  
  <p>which gives three output:</p>
  
  <pre><code>[1] " A vs B " " C vs D (EF) " " GH ( I vs J)"
  </code></pre>
  
  <p>The last match is incorrect. How can I fix this?</p>