title: How do I repeat a capturing group?
body: <p>I have an input string that looks something like this:</p>
  
  <pre><code>HLI6Ch60000Ch500C0Ch46400Ch30000Ch21888Ch10E79CS07LCU3Ch37880Ch27800Ch16480CS8CA00000000000000000000
  </code></pre>
  
  <p>Now I don't care about the part that follows the last letter <code>A</code>, it'll always be <code>A</code> and exactly 20 numbers that are of no use to me. I do, however, need the part before the last letter <code>A</code>, and ideally, I'd need it to be separated into two different captures, just like this:</p>
  
  <pre><code>1: HLI6Ch60000Ch500C0Ch46400Ch30000Ch21888Ch10E79CS07
  2: LCU3Ch37880Ch27800Ch16480CS8C
  </code></pre>
  
  <p>The only way to identify these matches is that they end with characters <code>CS</code> followed by two hexadecimal characters. I thought that a regular expression like <code>(.+?CS.{2})+</code> (or <code>(.+?CS[[:xdigit:]]{2})+</code>) would do the job but when tried on <a href="http://www.regex101.com" rel="nofollow">www.regex101.com</a>, it only captures the last group and gives the following warning:</p>
  
  <p><strong><em>Note</strong>: A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data</em></p>
  
  <p>Which I thought suggests that I should use regular expression like <code>((.+?CS.{2})+)</code> instead and I mean – sure, now I get two captures, but they look like this:</p>
  
  <pre><code>1: HLI6Ch60000Ch500C0Ch46400Ch30000Ch21888Ch10E79CS07LCU3Ch37880Ch27800Ch16480CS8C
  2: LCU3Ch37880Ch27800Ch16480CS8C
  </code></pre>
  
  <p>Meaning the first one is… slightly longer than I'd like it to be. If it helps in any way, I should point out that the final regular expression will be part of an iOS application so an instance of <code>NSRegularExpression</code> class will be used – not sure if that's a helpful information at all, it's just that I know that <code>NSRegularExpression</code> doesn't support every part of the world of regular expressions.</p>