Regular expression works in VB but not C #
I have the following regex to test the filename:
^ (([a-zA-Z]: | \) \)? (((.) | (..) | ([^ \ /: * \? "\ | <>.] (([^ \ /: * \?" \ | <>.]) | ([^ \ /: * \? "\ | <>] [^ \ /: * \?" \ | <>.]))?)) \) [^ \ /: * \? "\ | <>.] (([^ \ /: * \?" \ | <>.]) | ([^ \ /: * \? "\ | <>] * [^ \ /: * \? "\ | <>.]))? $
I can get it to work in VB.NET, but not C #. I can't figure out why it works in one but not the other.
VB code:
Regex.Matches("c:\temp\abc.exe", "^(([a-zA-Z]:|\\)\\)?(((\.)|(\.\.)|([^\\/:\*\?""\|<>\. ](([^\\/:\*\?""\|<>\. ])|([^\\/:\*\?""\|<>]*[^\\/:\*\?""\|<>\. ]))?))\\)*[^\\/:\*\?""\|<>\. ](([^\\/:\*\?""\|<>\. ])|([^\\/:\*\?""\|<>]*[^\\/:\*\?""\|<>\. ]))?$")
C # code:
Regex.Matches("c:\temp\abc.exe", @"^(([a-zA-Z]:|\\)\\)?(((\.)|(\.\.)|([^\\/:\*\?""\|<>\. ](([^\\/:\*\?""\|<>\. ])|([^\\/:\*\?""\|<>]*[^\\/:\*\?""\|<>\. ]))?))\\)*[^\\/:\*\?""\|<>\. ](([^\\/:\*\?""\|<>\. ])|([^\\/:\*\?""\|<>]*[^\\/:\*\?""\|<>\. ]))?$");
As far as I can tell, the templates are identical in both languages with escaping. When I run the VB code, I get a match. When I run the C # code, I get nothing.
Can anyone see what I am missing?
0
a source to share