SYNTAX: !regex -p
eg: !regex 127.0.0.1 -p /^\b(\d+.\d+.\d+.\d+)\b$/
Regular Expression Tester
By: Phil (#dot100 @ QuakeNet)
Bug reports/feature requests - phil@dot100.co.uk
Examples:
(@phil) !regex 127.0.0.1:27015 password de_dust2 -p /([0-9]+.[0-9]+.[0-9]+.[0-9]+\:[0-9]+) (\S+) (\S+)/
(@bot) Tested "127.0.0.1:27015 password de_dust2 -p" with pattern: /([0-9]+.[0-9]+.[0-9]+.[0-9]+\:[0-9]+) (\S+) (\S+)/ - result: 1
(@bot) Result 1: 127.0.0.1:27015
(@bot) Result 2: password
(@bot) Result 3: de_dust2
(14:43:01) (@dot100|phil) !regex a very long string or phrase to test and see if my regex works -p /(\w+)/g
(14:43:02) (+GamerFM) Tested "a very long string or phrase to test and see if my regex works" with pattern: /(\w+)/g - result: 14
(14:43:02) (+GamerFM) Result 1: a
(14:43:02) (+GamerFM) Result 2: very
(14:43:02) (+GamerFM) Result 3: long
(14:43:02) (+GamerFM) Result 4: string
(14:43:03) (+GamerFM) Result 5: or
(14:43:05) (+GamerFM) -- Result spew truncated at 5 results --
**
UPDATE: Thanks to bindi for finding the regex which crashes mIRC.
**
alias regex.threshold { !return 5 }
on *:TEXT:!regex*:#: {
if (!$2 || !$3) { .msg $chan Syntax: !regex <data> -p <pattern> | halt }
var %x = 1
while ($gettok($2-,%x,32)) {
if ($ifmatch == -p) { var %pos = %x }
inc %x
}
if (!%pos) { .msg $chan No $qt(-p) found. | halt }
var %data = $gettok($2-,$+(1,-,$calc(%pos - 1)),32)
var %pattern = $gettok($2-,$+($calc(%pos + 1),-),32)
msg $chan Tested $qt(%data) with pattern: %pattern - result: $regex(%data,%pattern)
if (*/((?(?!a).))*/* iswm %pattern) { msg $chan Disallowed Regex. }
if ($regex(%data,%pattern)) && ($regml(0) != 0) {
var %x = 1
while ($regml(%x)) {
msg $chan Result %x $+ : $ifmatch
if (%x == $regex.threshold) { msg $chan -- Result spew truncated at $v2 results -- | break }
inc %x
}
}
}