Regular Expression Match Capture Index Property Returns 0 Instead Of -1 In C#
Yesterday, while working on Regex Index property, I encountered a weird problem. Supposedly, string.indexOf(string variable) returns -1 value if there's no occurrence of such substring. However, using
returns 0 if instead of -1 if no such substring occurs. The solution was pointed out in stack overflow: Return index position of string after match found
using Group.Success in which case returns a boolean value.
So, here's the tip:
Greg
Regex.Match(source.ToLower(), @"regex pattern").Index
So, here's the tip:
if ((Regex.Matches(source.ToLower(), @"<ol[^>]*>").Count < 1) && (Regex.Matches(source.ToLower(), @"<ul[^>]*>").Count > 0)) { if (Regex.Match(source.ToLower(), @"<ul[^>]*>", RegexOptions.IgnoreCase).Success) { // your if statements here.... :) } }
Comments
Post a Comment