Related (but slightly different):
Javascript Regex: surround @_____, #_____ and http: // ______ with anchor tags in one go?
I would like to surround all instances of @_______, #________ and http://________with anchor tags. A few passes are okay with me.
For example, consider this Twitter post:
The quick brown fox @Spreadthemovie jumps over the lazy dog
Running with the desired regular expression pattern will give:
The quick brown fox <a href="blah/Spreadthemovie">@Spreadthemovie</a> jumps over the lazy
dog <a href="blah/cow">#cow</a>, <a href="blah/http://bit.ly/bC9Dy">http://bit.ly/bC9Dy</a>
Only surrounding words starting with @, # or http: // so dog@gmail.com will not become dog@gmail.com. Also pay attention to how " #cow," turned into " <a href=urlB>#cow</a>," ... I want only alpha-numeric characters to be at the end of each anchored labeled substring. Also note the href attribute.
If possible, include the actual javascript code with the regex template and replace the function.
Many thanks! This problem haunted me for a while
source
share