2010-01-26 04:39:26 +00:00
|
|
|
'''
|
|
|
|
regular.py
|
|
|
|
|
|
|
|
skybot plugin for testing regular expressions
|
|
|
|
by Ipsum
|
|
|
|
'''
|
|
|
|
|
|
|
|
import thread
|
|
|
|
import codecs
|
|
|
|
import re
|
|
|
|
|
|
|
|
from util import hook
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-26 22:57:47 +00:00
|
|
|
@hook.command('re')
|
2010-01-26 04:39:26 +00:00
|
|
|
def reg(bot, input):
|
2010-01-26 22:57:47 +00:00
|
|
|
".re <regex> <string> -- matches regular expression in given <string> (seperate regex and string by 2 spaces)"
|
2010-01-26 04:39:26 +00:00
|
|
|
|
|
|
|
m = ""
|
|
|
|
|
2010-01-26 22:57:47 +00:00
|
|
|
if len(input.msg) < 3:
|
2010-01-26 04:39:26 +00:00
|
|
|
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__
|