开发者

replace plain urls with links having the text truncated

I am using the answers from this question How to replace plain URLs with links? but I want the links to be truncated. For example, if the link is longer than 25 characters, I want to show https://stackover开发者_Go百科flow.com/questions/...

How can I call a slice or substring on a result from a regex?


You can do something like:

myString.replace(/(?=http://.....)(\S{,25})\S*/g, '<a href="$0">$1</a>');

Though this won't show the elipsis

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜