Regex Match throwing exception with my pattern

Tags: c# regex match

I'm calling match below but I'm getting an exception that says "Internal error in the expression evaluator." when I try and pass "*_sales.txt" in as config.FileNamePattern. For some reason it doesn't like this pattern. What am I doing wrong? I tried passing it in with and without the '@' symbol.

Match match = Regex.Match(Path.GetFileName(file), @config.FileNamePattern, RegexOptions.IgnoreCase);


The second argument to Regex.Match is a regex pattern. You pass "*_sales.txt" that starts with a * that you think is a wildcard, but in fact is a quantifier matching zero or more occurrences. It cannot quantifier the beginning of a pattern, it is an invalid regex.

You might want to use


to check if a string ends with _sales.txt. Also, adding RegexOptions.RightToLeft to your options can optimize matching the string from the end.

Note the . is escaped to match a literal dot.

Also, a verbatim string literal is the best way to define regex patterns as you only have to escape the special chars once.

Try as below and let me know

var a = new Array();
a[0]= new Array();


The key word that you're apparently missing is "epsilon." If you search on Python epsilon value then it returns a links to StackOverflow: Value for epsilon in Python near the top of the results in Google.

Obviously it helps if you understand how the term is associated with this concept.

This video can help you solving your question :)
By: admin