Skip to content

Commit

Permalink
urlcopy: Optimize and better document pattern matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
funkydude committed Feb 13, 2017
1 parent 7f702ad commit d52e80e
Showing 1 changed file with 54 additions and 4 deletions.
58 changes: 54 additions & 4 deletions urlcopy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,73 @@ BCM.modules[#BCM.modules+1] = function()
-- valid (but invalid in their location) things ".", "/", "," to prevent words like "lol...", "true./" and "yes.," becoming a URL.
-- As of the introduction of the S.E.L.F.I.E camera we now require at least 2 valid letters e.g. yo.hi
local filterFunc = function(_, _, msg, ...)
-- [ ]a.b.c.d/e
local newMsg, found = gsub(msg,
"( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]*%.?[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~%d]*%.?[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+/[^ \"%^`{}%[%]\\|<>]+)",
"( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~%d]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+/[^ \"%^`{}%[%]\\|<>]+)",
"%1|cffffffff|Hbcmurl~%2|h[%2]|h|r"
)
if found > 0 then return false, newMsg, ... end
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^`{}%[%]\\|<>%(%)%*!%?_%+#&;~%d]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+/[^ \"%^`{}%[%]\\|<>]+)",
"%1|cffffffff|Hbcmurl~%2|h[%2]|h|r"
)
if found > 0 then return false, newMsg, ... end
-- ^a.b.c/d
newMsg, found = gsub(msg,
"^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]*%.?[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]*%.?[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+",
"^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+/[^ \"%^`{}%[%]\\|<>]+",
"|cffffffff|Hbcmurl~%1|h[%1]|h|r"
)
if found > 0 then return false, newMsg, ... end
-- [ ]a.b/c
newMsg, found = gsub(msg,
"( )([^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+/[^ \"%^`{}%[%]\\|<>]+)",
"%1|cffffffff|Hbcmurl~%2|h[%2]|h|r"
)
if found > 0 then return false, newMsg, ... end
-- ^a.b/c
newMsg, found = gsub(msg,
"^[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+/[^ \"%^`{}%[%]\\|<>]+",
"|cffffffff|Hbcmurl~%1|h[%1]|h|r"
)
if found > 0 then return false, newMsg, ... end
-- [ ]a.b.c.d
newMsg, found = gsub(msg,
"( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+)",
"%1|cffffffff|Hbcmurl~%2|h[%2]|h|r"
)
if found > 0 then return false, newMsg, ... end
-- ^a.b.c.d
newMsg, found = gsub(msg,
"^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+",
"|cffffffff|Hbcmurl~%1|h[%1]|h|r"
)
-- [ ]a.b.c
newMsg, found = gsub(msg,
"( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+)",
"%1|cffffffff|Hbcmurl~%2|h[%2]|h|r"
)
if found > 0 then return false, newMsg, ... end
-- ^a.b.c
newMsg, found = gsub(msg,
"^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+",
"|cffffffff|Hbcmurl~%1|h[%1]|h|r"
)
-- [ ]a.b
newMsg, found = gsub(msg,
"( )([^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+)",
"%1|cffffffff|Hbcmurl~%2|h[%2]|h|r"
)
if found > 0 then return false, newMsg, ... end
-- ^a.b
newMsg, found = gsub(msg,
"^[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d][^ %%'%-=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:%d]+",
"|cffffffff|Hbcmurl~%1|h[%1]|h|r"
)
if found > 0 then return false, newMsg, ... end
Expand Down

0 comments on commit d52e80e

Please sign in to comment.