Reputation: 19664
I am trying to match on a string that begins with ./media
I have the following Regular expression:
bool match = Regex.IsMatch(@"^\./media", imgSourcePath);
My source string looks like: ./media/somefile.png
When I test this expression in other tools it works as expected. However a match is never found in C# source implementation. Can someone tell me why?
Thanks!
Upvotes: 0
Views: 720
Reputation: 1782
Your parameters appear to be backwards: Regex.IsMatch(String input, String pattern)
. Try this:
var m = Regex.IsMatch("./media", "(./media)(.*?)", RegexOptions.IgnoreCase |
RegexOptions.Singleline);
MessageBox.Show(m.ToString()); //displays true
Upvotes: 2
Reputation: 1887
http://msdn.microsoft.com/en-us/library/sdx2bds0.aspx#Y30
You have the input and pattern backwards. The string you want to search for a match should be the first parameter, and the pattern to use should be the second.
Upvotes: 1