Added re command.

This commit is contained in:
Jeremy Fincher 2003-04-11 21:17:37 +00:00
parent e5c58089ce
commit 62c407d694

View File

@ -39,6 +39,8 @@ Commands include:
from baseplugin import * from baseplugin import *
import re
import privmsgs import privmsgs
import callbacks import callbacks
@ -72,6 +74,19 @@ class Utilities(callbacks.Privmsg):
i = int(i) i = int(i)
args = callbacks.tokenize(rest) args = callbacks.tokenize(rest)
irc.reply(msg, args[i]) 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 Class = Utilities