From fefd4ae35b9ad01f11a589d0e6d499362d8590f7 Mon Sep 17 00:00:00 2001 From: Sfan5 Date: Sat, 1 Jun 2013 19:54:38 +0200 Subject: [PATCH] [RUtils] Try to find as many possible matches (!regex) --- rutils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rutils.py b/rutils.py index 0a663f5..69a2351 100755 --- a/rutils.py +++ b/rutils.py @@ -217,18 +217,18 @@ def regex(phenny, input): return q = input.group(2).encode('utf-8') rgx = q[:q.find("\x02")] - msg = q[q.find("\x02")+1:] - if rgx == "" or msg == "": + txt = q[q.find("\x02")+1:] + if rgx == "" or txt == "": return phenny.reply("Give me a regex and a message seperated by \x02") try: r = re.compile(rgx) except BaseException as e: return phenny.reply("Failed to compile regex: " + e.message) - m = r.match(msg) - if m == None: + m = list(e.groups()[0] for e in list(re.finditer(rgx, txt))) + if m == []: return phenny.say("false") else: - return phenny.say("true groups=[" + ', '.join((repr(e) for e in m.groups())) + "]") + return phenny.say("true groups=[" + ', '.join((repr(e) for e in m)) + "]") regex.commands = ['re','regex'] regex.priority = 'low'