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

View File

@ -635,8 +635,15 @@ function updateChatFilters(entries) {
.appendTo($("<td/>").appendTo(newfilt)); .appendTo($("<td/>").appendTo(newfilt));
var cback = (function(regex, replace) { return function() { var cback = (function(regex, replace) { return function() {
if(regex.val() && replace.val()) { 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 { try {
var dummy = new RegExp(regex.val(), "g"); var dummy = new RegExp(re, flags);
} }
catch(e) { catch(e) {
alert("Invalid regex: " + e); alert("Invalid regex: " + e);