[RUtils] Try to find as many possible matches (!regex)
parent
dbc74695b4
commit
fefd4ae35b
10
rutils.py
10
rutils.py
|
@ -217,18 +217,18 @@ def regex(phenny, input):
|
||||||
return
|
return
|
||||||
q = input.group(2).encode('utf-8')
|
q = input.group(2).encode('utf-8')
|
||||||
rgx = q[:q.find("\x02")]
|
rgx = q[:q.find("\x02")]
|
||||||
msg = q[q.find("\x02")+1:]
|
txt = q[q.find("\x02")+1:]
|
||||||
if rgx == "" or msg == "":
|
if rgx == "" or txt == "":
|
||||||
return phenny.reply("Give me a regex and a message seperated by \x02")
|
return phenny.reply("Give me a regex and a message seperated by \x02")
|
||||||
try:
|
try:
|
||||||
r = re.compile(rgx)
|
r = re.compile(rgx)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
return phenny.reply("Failed to compile regex: " + e.message)
|
return phenny.reply("Failed to compile regex: " + e.message)
|
||||||
m = r.match(msg)
|
m = list(e.groups()[0] for e in list(re.finditer(rgx, txt)))
|
||||||
if m == None:
|
if m == []:
|
||||||
return phenny.say("false")
|
return phenny.say("false")
|
||||||
else:
|
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.commands = ['re','regex']
|
||||||
regex.priority = 'low'
|
regex.priority = 'low'
|
||||||
|
|
Loading…
Reference in New Issue