<p>To see what file to invoke the unrar command on, one needs to determine which file is the first in the file set.</p>

<p>Here are some sample file names, of which - naturally - only the first group should be matched:</p>

<pre><code>yes.rar
yes.part1.rar
yes.part01.rar
yes.part001.rar

no.part2.rar
no.part02.rar
no.part002.rar
no.part011.rar
</code></pre>

<p>One (limited) way to do it with PCRE compatible regexps is this:</p>

<pre><code>.*(?:(?&lt;!part\d\d\d|part\d\d|\d)\.rar|\.part0*1\.rar)
</code></pre>

<p>This did not work in Ruby when I tested it at <a href="http://www.projects.aphexcreations.net/rejax/" rel="nofollow noreferrer">Rejax</a> however.</p>

<p>How would you write one <strong>Ruby compatible</strong> regular expression to match only the first file in a set of RAR files?</p>

I am no regex expert but here is my attempt
```
```
^(yes|no)\.(rar|part0*1\.rar)$
```
```
Replace "yes|no" with the actual file name. I matched it against your examples to see if it would only match the first set hence the "yes|no" in the regex.
UPDATE: fixed as per the comment. Not sure why the user would not know the filename so i did not fix that part...