title: Regex to optionally match 3 digits at the end of file name
body: <p>I can't for the life of me figure out how to get these to match:</p>
  
  <pre><code>File name without 3 digit end.jpg
  File name with 3 digit 123.gif
  Single 123.jpg
  Single.png
  </code></pre>
  
  <p>But not these:</p>
  
  <pre><code>Single 1.jpg
  Single 123b.gif
  More words 123b.png
  </code></pre>
  
  <p>The best I could so so far is this expression:</p>
  
  <pre><code>^[^\s]((?!\s{2})(?!,\S).)*\b(\p{L}+|\d{3})\.\w{3}$
  </code></pre>
  
  <p>But it fails to match <code>Single.png</code> and still matches <code>Single 123b.gif</code> and <code>More words 123b.png</code>.
  I think I understand why it doesn't work but I can't figure out how to get it right, and I have been struggling and Googling for 2 days.</p>
  
  <p>My full rules are: optionally exactly 3 digits at the end before the file extension, 3 letter file extension, no double spaces in the file name and a single space after but not before a comma.</p>