> What about simple replace?
>
> CurrentUrl = tagMatches[i].Result("${url}");
> myString = myString.replace(CurrentUrl, newUrl);
Ah thats what I did in the first place. However, when the href and the src
parts of the tag had identical beginning sections, both were replaced - in
my case I didn't want that to happen.
What I ended up doing was creating another reg expression to pull out just
the href url so that I could replace it. Just thought there may be any
easier way to use named capture groups to replace (not just capture) text.
Maybe there is, but as yet I've not a clue how to do it.
Thanks,
JJ
Alexey Smirnov - 04 Jun 2007 20:45 GMT
> > What about simple replace?
>
[quoted text clipped - 13 lines]
>
> JJ
I think there is one more possibility
Change your pattern to return all content in a groups
(?<textbefore>...)(?<url>...)(?<textafter>...)
In this case you could use the following replacement statement
string newUrl = "http://.......";
string result = reg_linkTags.Replace(text, "${textbefore}" + newUrl +
"${textafter}");
You can also use a MatchEvaluator delegate to custom string function
that can be called at each match to evaluate the replacement value.
string result = reg_linkTags.Replace(text, new
MatchEvaluator(NewUrl));
string NewUrl(Match m)
{
string x = m.Groups["Domain"].ToString();
...
return "something";
}
JJ - 05 Jun 2007 18:01 GMT
I didn't think of that. Thanks,
JJ
>> > What about simple replace?
>>
[quoted text clipped - 42 lines]
> return "something";
> }