Reputation: 4109
I'm looking for a way to split a Twitter permalink string on its final forward slash, so I can store the tweet_id. Two examples:
http://twitter.com/bloombergnews/status/55231572781170688
http://twitter.com/cnn/status/55231572781170688
Each URL has a similar format:
http://twitter.com/<screen_name>/status/<id_str>
With what regular expression would I easily capture every time?
Upvotes: 5
Views: 8441
Reputation: 161
REGX ? yes; simple one liner.
$url = 'http://twitter.com/bloombergnews/status/55231572781170688';
Perl
($f1 = $url) =~ s/^.*\///;
print $f1;
PHP
$f1 = preg_replace("/^.*\//","",$url);
echo $f1;
EDIT: backslashes didn't show; fixed in edit box by double \\ (wierd!)
Upvotes: 2
Reputation: 88697
This is not a job for regular expressions, IMHO.
I would do this:
$parts = explode('/', rtrim($url, '/'));
$id_str = array_pop($parts);
Upvotes: 23