Hello
I want to do a thing that looks very easy to do but because it needs Regex, I can't manage to do it.
I've got a HTML code in a string that contains links in this format:
Note: number of directories is not always just 1, it can be more.Code:<a href="/dir1/file">
and I want my program to change all occurences of links in a format like above to a format like that(it's just adding ".html"):
It would be very easy to do if only String.Replace() allowed me to use wildcards. If it did, it would be probably as easy as that:Code:<a href="/dir1/file.html">
I tried to use Regex, doing it this way:Code:str = str.Replace("a href=\"*\">", "a href=\"*.html\">"
but it doesn't work.Code:str = Regex.Replace(str, "<a href=\"(?<link>[a-zA-Z0-9_/-])\"", "<a href=${link}" + ".html\"");
Any help will be very appreciated.




Reply With Quote
