I want to split a text based on URLs.
So a text like
const text = 'hello world, testing https://stackoverflow.com/questions/ask this is prefix https://gmail.com final text'
should give
const result = [
'hello world, testing',
'https://stackoverflow.com/questions/ask',
'this is prefix',
'https://gmail.com',
'final text'
]
Basically any URL should split the text but the URL should also be included
I did try out a few things but was not able to create an algorithm for this.
/(http|https):\/\/[a-zA-Z0-9\-.]+\.[a-zA-Z]{2,3}(\/\S*)?/
I did try to split with this regex but its not consistent