title: Regex in R: replace only part of a pattern
body: <pre><code>s &lt;- "YXABCDXABCDYX"
  </code></pre>
  
  <p>I want to use a regular expression to return <code>ABCDABCD</code>, i.e. 4 characters on each side of central <code>"X"</code> but not including the <code>"X"</code>.
  Note that <code>"X"</code> is always in the center with 6 <strong>letters</strong> on each side. </p>
  
  <p>I can find the central pattern with e.g. <code>"[A-Z]{4}X[A-Z]{4}"</code>, but can I somehow let the return be the first and third group in <code>"([A-Z]{4})(X)([A-Z]{4})"</code>?</p>