Skip to content

Commit 01ee330

Browse files
committed
modify regex to accept stric words option
1 parent 92d4b30 commit 01ee330

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

jquery.highlighttextarea.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
ranges: {},
5050
color: '#ffff00',
5151
caseSensitive: true,
52+
wordsOnly: false,
5253
resizable: false,
5354
id: '',
5455
debug: false
@@ -62,10 +63,14 @@
6263
Highlighter.prototype.highlight = function() {
6364
var text = Utilities.htmlEntities(this.$el.val()),
6465
that = this;
65-
66+
that.spacer = '';
67+
if (this.settings.wordsOnly ) {
68+
that.spacer = '\\b';
69+
}
70+
6671
$.each(this.settings.words, function(color, words) {
6772
text = text.replace(
68-
new RegExp('('+ words.join('|') +')', that.regParam),
73+
new RegExp(that.spacer+'('+ words.join('|') +')'+that.spacer, that.regParam),
6974
'<mark style="background-color:'+ color +';">$1</mark>'
7075
);
7176
});

0 commit comments

Comments
 (0)