How to replace plain URLs with links?

前端 未结 24 2304
生来不讨喜
生来不讨喜 2020-11-21 05:42

I am using the function below to match URLs inside a given text and replace them for HTML links. The regular expression is working great, but currently I am only replacing t

24条回答
  •  盖世英雄少女心
    2020-11-21 05:52

    Correct URL detection with international domains & astral characters support is not trivial thing. linkify-it library builds regex from many conditions, and final size is about 6 kilobytes :) . It's more accurate than all libs, currently referenced in accepted answer.

    See linkify-it demo to check live all edge cases and test your ones.

    If you need to linkify HTML source, you should parse it first, and iterate each text token separately.

提交回复
热议问题