From 4ffc5fe5bf16ec3b5716f637a8cd55a688925918 Mon Sep 17 00:00:00 2001 From: ipsum Date: Mon, 25 Jan 2010 23:39:26 -0500 Subject: [PATCH] Added regular expressions plugin --- plugins/regular.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 plugins/regular.py diff --git a/plugins/regular.py b/plugins/regular.py new file mode 100644 index 0000000..ccfba87 --- /dev/null +++ b/plugins/regular.py @@ -0,0 +1,38 @@ +''' +regular.py + +skybot plugin for testing regular expressions +by Ipsum +''' + +import thread +import codecs +import re + +from util import hook + + + +@hook.command +def reg(bot, input): + ".reg -- matches regular expression in given (seperate regex and string by 2 spaces)" + + m = "" + + if len(input.msg) < 4: + return reg.__doc__ + + query = input.inp.partition(" ") + + + if query[2] != "": + r = re.compile(query[0]) + + matches = r.findall(query[2]) + for match in matches: + m += match + "|" + + return m.rstrip('|') + + else: + return reg.__doc__ \ No newline at end of file