Skip to content

Instantly share code, notes, and snippets.

@mala
Created September 24, 2010 11:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mala/595234 to your computer and use it in GitHub Desktop.
Save mala/595234 to your computer and use it in GitHub Desktop.
use Data::Dumper;
my @r;
my $text = q{@hoge http://example.com/#@hoge/ aaa #hash aaa @hogehoge aaa http://example.com/};
my $re = qr{(http://[A-Za-z0-9_\-\~\.\%\?\#\@/]+(?{push @r, ["HTTP", @-,@+] })|(?:^|\s)\@[A-Za-z0-9_]+(?{push @r,["AT", @-,@+]})|(?:^|\s)#[A-Za-z0-9_]+(?{push @r,["HashTag",@-,@+]}))};
warn $text;
() = $text =~/$re/g;
warn Dumper @r;
for (@r) {
warn substr $text, $_->[1], ($_->[2] - $_->[1]);
}
__END__
@hoge http://example.com/#@hoge/ aaa #hash aaa @hogehoge aaa http://example.com/ at twitter-text-parser.pl line 7.
$VAR1 = [
'AT',
'0',
'5',
undef
];
$VAR2 = [
'HTTP',
'6',
'32',
undef
];
$VAR3 = [
'HashTag',
'36',
'42',
undef
];
$VAR4 = [
'AT',
'46',
'56',
undef
];
$VAR5 = [
'HTTP',
'61',
'80',
undef
];
@hoge at twitter-text-parser.pl line 12.
http://example.com/#@hoge/ at twitter-text-parser.pl line 12.
#hash at twitter-text-parser.pl line 12.
@hogehoge at twitter-text-parser.pl line 12.
http://example.com/ at twitter-text-parser.pl line 12.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment