0

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://stackoverflow.com/questions/...

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

Community
  • 1
  • 1
hb922
  • 989
  • 1
  • 11
  • 23

1 Answers1

0

You can do something like:

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

Though this won't show the elipsis

Jacob Eggers
  • 9,062
  • 2
  • 25
  • 43