title: Matching from last instance of character if present to validate filename with extension in regex
body: <p>I am trying to limit the user from uploading <code>Long named files</code> and <code>unaccepted file extensions</code> using a regular expression validator in Asp.net 2.0 Webforms. I wanted the <code>filename to be withing 30</code> characters[restriction due to Db Design] and extensions match <code>png,jpeg,zip,rar,7z</code>.I came up with this regular expression which makes sure filename is valid character and then comes <code>.</code> literal period then the extension.</p>
  
  <p><code>^[\w_]{3,28}\.(pdf|jpeg|png)$</code></p>
  
  <p><strong>Update:</strong>
  i came up with this regex that matches even last instance only that even long filenames get validated</p>
  
  <pre><code>(\\(?!.*\\)|)[\w_]{3,30}\.(pdf|jpeg|jpg|pdf)$
  </code></pre>
  
  <p><strong>Update:</strong> Even this works just that fileName does not get limited to 30 characters</p>
  
  <pre><code>[\w]{3,30}\.(pdf|jpeg|jpg|pdf)(?=)
  </code></pre>
  
  <p><strong>info:</strong> It even validated <code>c:\fakePath\stackoverflowstackoverflowstackoverflowstackoverflow</code> btw it highlighted last 30 characters in fileName.</p>
  
  <p>The problem was that i want the validation to be done on client at time of uploading hence <code>EnableClientScript = True</code> , but to my surprise the fileUpload.value which the control validates was totally different in most of the browsers.</p>
  
  <p>Firefox reports: filename.extension as expected,</p>
  
  <p>Internet Explorer reported the Full Path to File</p>
  
  <p>chrome reports C:\fakePath\fileName.extension</p>
  
  <p>Now how do i write a expression for this, my idea was to look for last instance of the <code>\</code> character if present in the value then begin form there. But my knowledge of Regex is totally limited to the basics. could someone correct me and provide a working regex,</p>
  
  <p><strong>Note:</strong>
  Pls , before providing one make sure it met my requirements, works cross browser and validates on clientSide.</p>