diff --git a/js/client-chat.js b/js/client-chat.js index f2b2765f2..bd9e093ca 100644 --- a/js/client-chat.js +++ b/js/client-chat.js @@ -253,7 +253,7 @@ var highlights = Tools.prefs('highlights') || []; if (!app.highlightRegExp) { try { - app.highlightRegExp = new RegExp('\\b(' + highlights.join('|') + ')\\b', 'i'); + this.updateHighlightRegExp(highlights); } catch (e) { // If the expression above is not a regexp, we'll get here. // Don't throw an exception because that would prevent the chat @@ -267,6 +267,13 @@ } return ((highlights.length > 0) && app.highlightRegExp.test(message)); }, + updateHighlightRegExp: function (highlights) { + // Enforce boundary for match sides, if a letter on match side is + // a word character. For example, regular expression "a" matches + // "a", but not "abc", while regular expression "!" matches + // "!" and "!abc". + app.highlightRegExp = new RegExp('(?:\\b|(?!\\w))(?:' + highlights.join('|') + ')(?:\\b|\\B(?!\\w))', 'i'); + }, // chat history @@ -711,7 +718,7 @@ highlights = highlights.concat(targets.slice(1)); this.add("Now highlighting on: " + highlights.join(', ')); // We update the regex - app.highlightRegExp = new RegExp('\\b(' + highlights.join('|') + ')\\b', 'i'); + this.updateHighlightRegExp(highlights); break; case 'delete': var newHls = []; @@ -723,7 +730,7 @@ highlights = newHls; this.add("Now highlighting on: " + highlights.join(', ')); // We update the regex - app.highlightRegExp = new RegExp('\\b(' + highlights.join('|') + ')\\b', 'i'); + this.updateHighlightRegExp(highlights); break; default: // Wrong command diff --git a/js/client.js b/js/client.js index 1ce16b2a0..0774ece14 100644 --- a/js/client.js +++ b/js/client.js @@ -185,7 +185,7 @@ if (!self.get('named')) { self.nameRegExp = null; } else { - self.nameRegExp = new RegExp('\\b' + Tools.escapeRegExp(self.get('name')) + '\\b', 'i'); + self.nameRegExp = new RegExp('(?:\\b|(?!\\w))' + Tools.escapeRegExp(self.get('name')) + '(?:\\b|\\B(?!\\w))', 'i'); } }); },