Allow custom regex flags

Fixes Issue #29
For example, match "word" without case sensitivity, match globally:
word/ig
If you want to match a literal slash, escape it with a backslash: \/
This commit is contained in:
calzoneman 2013-04-16 11:02:00 -05:00
parent 6ae16d5671
commit 78ecc042d6
2 changed files with 20 additions and 6 deletions

View file

@ -801,7 +801,7 @@ Channel.prototype.move = function(data) {
Channel.prototype.tryMove = function(user, data) {
if(!Rank.hasPermission(user, "queue") &&
this.leader != user &&
this.leader != user &&
(!this.openqueue ||
this.openqueue || !this.opts.qopen_allow_move)) {
return;
@ -863,7 +863,7 @@ Channel.prototype.trySetLock = function(user, data) {
if(!Rank.hasPermission(user, "qlock")) {
return;
}
if(data.locked == undefined) {
return;
}
@ -906,8 +906,15 @@ Channel.prototype.tryChangeFilter = function(user, data) {
}
if(data.cmd == "update") {
var re = data.filter[0];
var flags = "g";
var slash = re.lastIndexOf("/");
if(slash > 0 && re[slash-1] != "\\") {
flags = re.substring(slash+1);
re = re.substring(0, slash);
}
try {
data.filter[0] = new RegExp(data.filter[0], "g");
data.filter[0] = new RegExp(re, flags);
}
catch(e) {
return;
@ -929,7 +936,7 @@ Channel.prototype.tryUpdateOptions = function(user, data) {
this.opts[key] = data[key];
}
}
this.broadcastOpts();
}
@ -959,7 +966,7 @@ Channel.prototype.tryChat = function(user, data) {
if(user.name == "") {
return;
}
if(data.msg == undefined) {
return;
}

View file

@ -635,8 +635,15 @@ function updateChatFilters(entries) {
.appendTo($("<td/>").appendTo(newfilt));
var cback = (function(regex, replace) { return function() {
if(regex.val() && replace.val()) {
var re = regex.val();
var flags = "g";
var slash = re.lastIndexOf("/");
if(slash > 0 && re[slash-1] != "\\") {
flags = re.substring(slash+1);
re = re.substring(0, slash);
}
try {
var dummy = new RegExp(regex.val(), "g");
var dummy = new RegExp(re, flags);
}
catch(e) {
alert("Invalid regex: " + e);