I saw a few posts on this but they were for PHP (I need JavaScript (actually ActionScript (…because ActionScript extends JavaScript))) so my question is how to only capture up to a comma, period, question mark or exclamation point.
This is what I have so far,
instructionText.replace(/(https?:\/\/\w.*[\w])/gi, "<a href='$1' target='_blank'>$1</a>");
But when I use the text, “Visit http://www.google.com. Hello world” it captures the hello world part.
The result of the capture group above is “http://google.com. Hello world “. Obviously I don’t want anything after the URL. They should be simple URL’s.
Mainly, I just want to add a check for any of these “.,!?” or a space character and end the capture group. It doesn’t have to be perfect.
BTW Not sure if you have something to test your RegEx first but if not you can use RegExr.
Assuming no space in the urls and a space or end of string after them:
It captures ‘http[s]://’ and non-space characters as few times as possible until looking ahead there is optionally one of
.,!?, and then a space or the end of string.