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 *
import re
import privmsgs
import callbacks
@ -73,6 +75,19 @@ class Utilities(callbacks.Privmsg):
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
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: