in reply to Reg expression to replace URLs with Anchor tags in Tweets

Your regexp looks like how you might accomplish the task using sed(1), capture strings in perl are referenced as $n in the substitution - where n is 1..9.

Your regexp is capturing everything from the 'http' string, hence your regexp:

s/(http.*)/<a href=\"\1\">\1<\/a>/;
should read:
s/(http\S+)/<a href="$1">$1<\/a>/;
In that way, the regexp will capture everything from the 'http' string to (but not including) the next whitespace char.

See perlre &/or perlretut.

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: Reg expression to replace URLs with Anchor tags in Tweets
by halfbaked (Sexton) on Apr 19, 2009 at 00:15 UTC
    Thanks Bloodnok, that's exactly what I was looking for.

    I want to avoid using a package to solve this problem because I have to do the same thing in some PHP code. I don't know of a PHP module that can do what I need, preg_replace will work using Perl regular expressions.

    This is one of those things I've been wanting to solve for awhile but kept putting it off.

    Thanks again,
    Keith