Skip to content

Commit

Permalink
Let's play with regex detecting moar regexes [status-regex-overflow]
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeballcode committed Nov 29, 2015
1 parent 0d9d1d7 commit db7135e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions public/javascript/WhatsappBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,40 @@ handlers.randColor = function () {
}
};

handlers.splitRegex = function (args) {
var parts = args.split(/\/(.+)\/(g?m?i?) (".*")/).filter(function (e) {
return !!e
});
if (parts.length === 0) {
whatsapp.sendMessage('No match!');
return;
}
if (!parts[parts.length - 1]) {
whatsapp.sendMessage('No match!');
return;
}
var regex;
try {
new RegExp(parts[0]);
} catch (e) {
whatsapp.sendMessage('Invalid regex!');
return;
}
if (parts.length === 3)
regex = new RegExp(parts[0], parts[1]);
else
regex = new RegExp(parts[0]);
var test = parts[parts.length - 1].replace(/^"(.*)"$/, '$1');
var regexParts = test.split(regex).filter(function (e) {
return !!e
});
console.log(regexParts);
if (!regexParts)
whatsapp.sendMessage('No match!');
else
whatsapp.sendMessage(regexParts.join(', '));
};

if (!whatsapp.isWatching)
whatsapp.startWatching();

Expand Down
2 changes: 1 addition & 1 deletion public/javascript/WhatsappUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function loadCORSWindow() {
}

function loadWhatsappAPI() {
whatsappUtils. requestSomething({
whatsappUtils.requestSomething({
url: 'http://localhost:3000/javascript/WhatsappAPI.js',
callback: function (e) {
window.initWhatsappAPI = window.eval('function getInit(){' + e + '\nreturn init;}; getInit();');
Expand Down

0 comments on commit db7135e

Please sign in to comment.