I'm kinda new to Regex and C#.
I'm trying to build a tool that goes through list of files, and after that retrun the name of the file if it contains a certain pattern, im using the block below to go through the list
var queryMatchingFiles =
from file in fileList
where file.Extension != ".dll" && file.Extension != ".pdb"
let fileText = File.ReadAllText(file.FullName)
let matches = Regex.Matches(fileText, pattern, RegexOptions.IgnoreCase)
where matches.Count > 0
select new {
name = file.FullName,
matchedValues =
from Match match in matches
select match.Value
};
Now the input for the pattern
in the file is .htc
, I know that a dot in Regex means any letter, i tried to do the to make sure the pattern is forced to be .htc
pattern = @"\b" + pattern + @"\b";
or
pattern = string.Format(@"\b" + pattern + @"\b");
and it still doesnt accept the dot in .htc
, any ideas how to topple this problem?
EDIT: Im not looking for the file extention, what im trying to do is scan through HTML and Text files content, and see if it contains certain words like .htc
EDIT 2: Thank you guys for your answers, pattern = Regex.Escape(".htc");
is what i was looking for!