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

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -