/// <summary> ///regular recursive matching/// </summary> /// <param name= "Dicval" >Returns a dictionary</param> /// <param name= "context" >the string to match</param> /// <param name= "I" >start matching from the first few regular expressions</param> /// <param name= "regexes" >Regular Expressions</param> Private Static voidREGEXSTR (refdictionary<string,string> Dicval,stringContextintIstring[] regexes) { if(I <= (regexes). Length-1) {regex regex=NewRegex (Replacestr (regexes[i)); MatchCollection MC=regex. Matches (context); foreach(Match minchMC) {foreach(stringNameinchRegex. Getgroupnames ())//looking for tagged groups if(name. StartsWith ("Val") ) Dicval.add (name, M.groups[name]. Value); Regexstr (refDicval, M.value, i +1, regexes); } } }
Invoke Example
stringHTMLData ="HTML";string[] regexes = { @".+?", @".+?", @".+?"};D ictionary<string,string> dicvalout =Newdictionary<string,string>(); Regexstr (refDicvalout, HTMLData,0, regexes);
Regular recursive matching