Making @Twitter Names Clickable
Here's a super quick Script Sunday for you: making @Twitter usernames clickable. Here's an example:
@scriptnode
@<href="http://twitter.com/scriptnode">scriptnode</a>
And here's how to do it in PHP and JavaScript:
PHP
That was easy! Now let's get to the more interesting JavaScript, which allows us to test inline!
JavaScript
You can run this code right here:
Some @test code
I'm awful at regular expressions; please do let me know if I could optimize somewhere or if I missed something.
Edit: + instead of *
I think you should use + rather than a *
With your current regex, even a single @ will match – and I don’t think that’s very useful =)
@Jani: thanks, good point!