C# code to linkify urls in a string

后端 未结 7 1401
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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 06:54

    It's not that easy as you can read in this blog post by Jeff Atwood. It's especially hard to detect where an URL ends.

    For example, is the trailing parenthesis part of the URL or not:

    • http​://en.wikipedia.org/wiki/PCTools(CentralPointSoftware)
    • an URL in parentheses (http​://en.wikipedia.org) more text

    In the first case, the parentheses are part of the URL. In the second case they are not!

提交回复
热议问题