Reputation: 26518
For one of my projects I want to use a regular expression to match a string like "REF:Sheet1!$C$6".
So far I have done
public static private bool IsCellReference()
{
string CELL_REFERENCE_PATTERN = @"REF:Sheet[1-9]!$[A-Z]$[0-9]";
Regex r = new Regex(CELL_REFERENCE_PATTERN);
Match m = r.Match("REF:Sheet1!$C$6");
if (m.Success) return true;
else return false;
}
but it is not working. It is returning false.
Where am I wrong?
Upvotes: 1
Views: 473
Reputation: 11612
You need to escape your $ signs.
REF:Sheet[1-9]!\$[A-Z]\$[0-9]
See Regular Expression Language Elements for more information
Also, this page is good for testing your regexes: A better .NET Regular Expression Tester
Upvotes: 5