Skip to content

Commit 34c04f3

Browse files
committed
Merge pull request #52 from Emmenemoi/master
modify regex to accept stric words option
2 parents fd490c1 + 01ee330 commit 34c04f3

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
@@ -53,6 +53,7 @@
5353
ranges: {},
5454
color: '#ffff00',
5555
caseSensitive: true,
56+
wordsOnly: false,
5657
resizable: false,
5758
id: '',
5859
debug: false
@@ -66,10 +67,14 @@
6667
Highlighter.prototype.highlight = function() {
6768
var text = Utilities.htmlEntities(this.$el.val()),
6869
that = this;
69-
70+
that.spacer = '';
71+
if (this.settings.wordsOnly ) {
72+
that.spacer = '\\b';
73+
}
74+
7075
$.each(this.settings.words, function(color, words) {
7176
text = text.replace(
72-
new RegExp('('+ words.join('|') +')', that.regParam),
77+
new RegExp(that.spacer+'('+ words.join('|') +')'+that.spacer, that.regParam),
7378
'<mark style="background-color:'+ color +';">$1</mark>'
7479
);
7580
});

0 commit comments

Comments
 (0)