As mentioned above, the use of delegation in regular expressions is matchevaluator. For details, refer
This is the most standard syntax: to customize a function, and then use this function delegate as a parameter to instantiate the matchevaluator object. Finally, you can use this object for parameter input during regular expression matching, manual processing of matching results.
Today we will introduce two easy-to-use writing methods. The use case is as follows: Reduce the number enclosed in parentheses in the string by 10:
StringS ="Sdlfk (23984) sdlkf (3) sldfk (15) weoif23948 (fsdlk) fdskjf (34) dlfk (432d) <br/>";
Response. Write (s );
RegExR = new RegEx (@"(? <= \ () \ D + (? = \))");
// 1, Lambda expression
MatchevaluatorMe = m => (Int. Parse (M. Value)-10). tostring ();
Response. Write (R. Replace (S, me ));
// 2, anonymous delegate
Response. Write (R. Replace (S,Delegate(MatchM) {return (Int. Parse (M. Value)-10). tostring ();}));
The output is as follows:
Sdlfk (23984) sdlkf (3) sldfk (15) weoif23948 (fsdlk) fdskjf (34) dlfk (432d)
Sdlfk (23974) sdlkf (-7) sldfk (5) weoif23948 (fsdlk) fdskjf (24) dlfk (432d)
Sdlfk (23974) sdlkf (-7) sldfk (5) weoif23948 (fsdlk) fdskjf (24) dlfk (432d)
No problem