Added re command.

This commit is contained in:
Jeremy Fincher 2003-04-11 21:17:37 +00:00
parent e5c58089ce
commit 62c407d694
1 changed files with 15 additions and 0 deletions

View File

@ -39,6 +39,8 @@ Commands include:
from baseplugin import *
import re
import privmsgs
import callbacks
@ -72,6 +74,19 @@ class Utilities(callbacks.Privmsg):
i = int(i)
args = callbacks.tokenize(rest)
irc.reply(msg, args[i])
def re(self, irc, msg, args):
"""<regexp> <text>
Returns all matches to <regexp> (in the form /regexp/flags) in text.
"""
(re, text) = privmsgs.getArgs(args, needed=2)
(_, re, flags) = re.split('/')
flag = 0
for c in flags:
flag &= getattr(re, c.upper())
r = re.compile(re, flag)
irc.reply(msg, ' '.join(r.findall(text)))
Class = Utilities