kasperEH
asked on
Regular expression only working in command prompt, not as variable
I want to check if a file name contains ~$ (tilde and dollar) as the first two characters, because then it's an Office backup file. That should be the following regular expression: ^\x7E\x24
When I create a c# program where I have to type in the regular expression in the command prompt like this it works fine:
Enter regular expression: ^\x7E\x24
Enter input for comparison: ~$rbar i Nordic.doc
However, when I use the same regular expression as a string variable in a c# program where fi is FileInfo, it doesn't work:
string reTildeDollar = @"^\x7E\x24";
if (Regex.IsMatch(reTildeDoll ar, fi.Name))
{
Console.WriteLine("Office backup file - will not be copied");
}
else
{
this.CopyToSharepoint(curr entDir.Ful lName,fi.N ame, fi.LastWriteTime);
}
Can anybody tell me why? (and yes, some of the files start with ~$)
When I create a c# program where I have to type in the regular expression in the command prompt like this it works fine:
Enter regular expression: ^\x7E\x24
Enter input for comparison: ~$rbar i Nordic.doc
However, when I use the same regular expression as a string variable in a c# program where fi is FileInfo, it doesn't work:
string reTildeDollar = @"^\x7E\x24";
if (Regex.IsMatch(reTildeDoll
{
Console.WriteLine("Office backup file - will not be copied");
}
else
{
this.CopyToSharepoint(curr
}
Can anybody tell me why? (and yes, some of the files start with ~$)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER