I have a regex expression that I’m trying to construct that processes a file path and tries to find a file path whose directory ends with “Processed” or “Failed”.
I have something like this…
static string PROCESSED_DIRECTORY = "Processed";
static string FAILURE_DIRECTORY = "Failed";
...
if (Regex.IsMatch(FileFullPath, String.Format(@"(.*)\\({0})|({1})$", PROCESSED_DIRECTORY, FAILURE_DIRECTORY)))....
This works fine.
However, I created an additional Regex expression because I am also trying to match the occurance of a file that is located in the Processed or Failed directory. The regex is not matching and I believe it has something to do with the pipe symbol. It matches when I check for either ‘Failed’ or ‘Processed’ without the pipe symbol.
For example: The following files don’t match
– C:\ftp\business\Processed\file.txt
– C:\ftp|business\Failed\file.txt
I would expect them to match.
if (Regex.IsMatch(FileFullPath, String.Format(@"(.*)\\({0}|{1})\\(.*)", PROCESSED_DIRECTORY, FAILURE_DIRECTORY)))
If I somehow could combine the two Regex queries into one to say “Match a path that ends with Failed’ or ‘Processed’ and also match a file that exists in the ‘Failed’ or ‘Processed’ directory”, that’d be amazing. Right now though, I’m content with having two separate regex calls and getting the second to work.
Works ok for me… Ran this in LINQPad:
Here’s a version that will look for either containing the processed/failed strings OR ending in \Processed|Failed\filename.ext: