 <p>You're confused about what first and second mean. In this expression:</p> <pre><code>"([^$]*(\\$[A-Za-z][A-Za-z0-9_]*))+" ^_______________________________^ this part </code></pre> <p>is the first parenthesizes subexpression and </p> <pre><code>"([^$]*(\\$[A-Za-z][A-Za-z0-9_]*))+" ^________________________^ this part </code></pre> <p>is the second. If a parenthesized subexpression gets used more than once as part of a <code>*</code>, <code>?</code>, <code>+</code>, or <code>{}</code> repetition operator, it's the last match that counts.</p> <p>If you want to match an arbitrary number of instances, than rather than using the <code>+</code> on the end of your regex, you simply need to call <code>regexec</code> multiple times, and use the ending offset of the previous run as your new starting point.</p>