Click here to Skip to main content
15,921,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get the file names like TestUploads(1).xls or TestUploads(2).xls etc. Im used the regular expressions for number .

I tried below code but it's not working.
Please any one help.

C#
if (Regex.IsMatch(FileUpload.FileName, "TestUploads(^[0-9]$).xls", RegexOptions.IgnoreCase))
               {
                     // My Code

               }
Posted

Try that instead:
C#
if (Regex.IsMatch(FileUpload.FileName, "^TestUploads\([0-9]+\)\.xls$", RegexOptions.IgnoreCase))
{
   // My Code
}

The problem was the '^' and '$' aroung '[0-9]': '^' and '$' respectively denotes the start and end of the input; when you place them inside an expression, nothing can match. There was also the need to escape parenthesis and point, since these characters have a special meaning inside the regular expression.
I also modified the regex to accept more than one digit between parenthesis.

When it comes to using and constructing regular expressions, you really should have a look at Expresso ; not only will it allow you to build your custom expressions, but also will it teach you some basics about them.
Here: Expresso[^]
 
Share this answer
 
v3
Comments
_Asif_ 15-May-14 9:38am    
It is not verifying the "(" and ")" characters but it is verifying "TestUploads1.xls"
Try this

C#
if (Regex.IsMatch(FileUpload.FileName, "^TestUploads\(([0-9])+\)+.xls$", RegexOptions.IgnoreCase))
               {
                     // My Code

               }
 
Share this answer
 
Comments
Bajid Khan 15-May-14 10:10am    
working fine .Thanq very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900