Regexp::Common::microsyntax - a collection of regular expressions for use with microblogging-style text (tweets, dents, microposts, etc.)
Version 0.02
use Regexp::Common qw(microsyntax); # Available patterns: user, hashtag, grouptag, slashtag # Get all users/hashtags/groups/slashtags mentioned in $post @users = $post =~ m/$RE{microsyntax}{user}/og; @hashtags = $post =~ m/$RE{microsyntax}{hashtag}/og; @groups = $post =~ m/$RE{microsyntax}{grouptag}/og; @slashtags = $post =~ m/$RE{microsyntax}{slashtag}/og; # Capture/extract individual elements (see Regexp::Common '-keep') my @usernames; while ($post =~ m/$RE{microsyntax}{user}{-keep => 1 }/go) { push @usernames, $3; } # Substitute/markup individual elements $post =~ s|$RE{microsyntax}{user}|<span class="user">$1</span>|go;
Please consult the manual of Regexp::Common for a general description of the works of this interface.
Do not use this module directly, but load it via Regexp::Common.
This module provides regular expressions for matching microblogging-style text (tweets, dents, microposts, etc.). It is based on the ruby twitter-text Regex class, with extensions to support features that Twitter doesn't support (like status.net !group tags, microsyntax.org slashtags, etc.).
Returns a pattern that matches @username handles. For this pattern and the next three, using '-keep' (see Regexp::Common) allows access to the following individual components:
Returns a pattern that matches #hashtags, with support for unicode hashtags. Note that all number hashtags are specifically excluded.
Returns a pattern that matches identica/status.net !group tags.
Returns a pattern that matches slashtags, as defined and documented at http://microsyntax.org/. These normally occur at the end of a post, with the first (but typically not the others) introduced by a slash e.g.
Sample post /via @person1 by @person2 cc @person3 @person4
The following slashtags are recognised:
For this pattern, using '-keep' allows access to the following individual components:
Gavin Carr <gavin@openfusion.com.au>
Please report any bugs or feature requests to bug-regexp-common-microsyntax at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Regexp-Common-microsyntax.
bug-regexp-common-microsyntax at rt.cpan.org
The Ruby twitter-text-rb library, http://github.com/mzsanford/twitter-text-rb/.
twitter-text-rb
Regexp::Common
Copyright 2011 Gavin Carr <gavin@openfusion.com.au>.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Regexp::Common::microsyntax, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Regexp::Common::microsyntax
CPAN shell
perl -MCPAN -e shell install Regexp::Common::microsyntax
For more information on module installation, please visit the detailed CPAN module installation guide.