c# - Replace multiple string with the same -
want want replace domain in text string hyperlink.
so domain.com
, www.domain.com
, http://domain.com
, http://www.domain.com
, etc. replaced <a href="http://www.domain.com">
is possible replace these @ once don't have bunch of replace statements? thought first replacing each unique placeholder , replacing link don't have worry re-replacing string.
or maybe regex? horrible @ regex example great if that's best.
alternatively, there better option i've not considered?
is same domain or loosely resembling address? if it's domain.com replace few possibilities listed
if it's shaped address try regex like
((http://)?(www\.)?([a-za-z0-9]+)\.([a-z]{1,2,3}))
and replace
<a href="\1">
(usually regex refer capturing groups (whatever inside parenthesis) $1 $2 $3 in visual studio it's \1 \2 \3)
this if using gui tool in visual studio, programatically have access groups of regex match , find group 1
but depends on text parsing is, cause match string of character 1 or more characters dot few lowercase letters
to more specific change ([a-z]{1,2,3}) (com|net|org) possible suffixes
so get
((http://)?(www\.)?([a-za-z0-9]+)\.(com|net|org))
Comments
Post a Comment