Re: brenbot create custom messages [message #466354 is a reply to message #466239] |
Thu, 19 April 2012 00:29 |
|
danpaul88
Messages: 5795 Registered: June 2004 Location: England
Karma:
|
General (5 Stars) |
|
|
In that specific example, yes. Each set of () in the regex is a capture group, allowing you to extract the part of the match that occurred within them. They can also be nested, which can be confusing when it comes to working out the number to use for $n to get the value you wanted in very complicated regexes.
Also the example shown is inefficient, it would be more efficiently written as follows;
sub iranstuff
{
my %args = %{$_[ ARG0 ]};
if ( $args{'line'} =~ m/^\[IRANSTUFF\]\[(.+)\](.+)$/ )
{
my $prefix = "09[04$109]09 ";
plugin::ircmsg ( $prefix . $2 , "A" );
}
}
(NB: off the top of my head so it might need tweaking to compile but you get the idea One regex to do the lot.)
[Updated on: Thu, 19 April 2012 00:41] Report message to a moderator
|
|
|