C# code to linkify urls in a string

后端 未结 7 1378
Happy的楠姐
Happy的楠姐 2020-11-28 06:17

Does anyone have any good c# code (and regular expressions) that will parse a string and \"linkify\" any urls that may be in the string?

相关标签:
7条回答
  • 2020-11-28 06:56

    This works for me:

    str = Regex.Replace(str,
                    @"((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)",
                    "<a target='_blank' href='$1'>$1</a>");
    
    0 讨论(0)
提交回复
热议问题