开发者

replace plain urls with links having the text truncated

开发者 https://www.devze.com 2023-04-06 12:21 出处:网络
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://stac

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

精彩评论

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