Regex Match throwing exception with my pattern

Tags: c# regex match
Question!

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);


Answers

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

@"_sales\.txt$"

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();
a[0].push(1);
a[0].push(2);
a[0].push(3);

console.log(a[0][0]);
console.log(a[0][1]);
console.log(a[0][2]);



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