Hello,
I have a regex and I want to modify the value of a named capture
before doing the regex.Replace.
So something like:
string text = Regex.Replace(oldText, myRegex, @"<a href="$1">$1</a>",
regexOptions);
Now I want to modify the value of the second $1 just in case it is too
long to display.
This doesn't work, but this is what I want to do somehow!
string text = Regex.Replace(oldText, myRegex,
String.Format(@"<a href="$1">{0}</a>",
MyFunction("$1")),
regexOptions);
Marc Gravell - 10 Apr 2008 22:26 GMT
Try:
string text = Regex.Replace(oldText, myRegex, delegate (Match
match) {
string capture1 = match.Captures[0].Value;
return string.Format(@"<a href=""{0}"">{1}</a>",
capture1, MyFunction(capture1));
}, regexOptions);
Marc
DotNetNewbie - 21 Apr 2008 18:36 GMT
> Try:
>
[quoted text clipped - 6 lines]
>
> Marc
Marc, it didn't compile for some reason (i.e. there is not method that
takes in a delegate?)