C# code to linkify urls in a string

后端 未结 7 1386
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\-\@?^=%&/~\+#])?)",
                    "$1");
    

提交回复
热议问题