c# - How do you modify the matched string using Regex.Replace? -
say want convert these strings:
www.myexample.com , http://www.myexample.com
into:
<a href='http://www.myexample.com'>http://www.myexample.com</a>
using regex.replace
i've come this:
regex.replace(string, pattern, "<a href=\"$&\">$&</a>")
my problem don't know how check if matched string $& starts http:// , adds if necessary.
any ideas?
if don't have consider https
or things that, maybe use this:
regex.replace(string, @"(?:http://)?(.+)", "<a href=\"http://$1\">http://$1</a>")
Comments
Post a Comment