Skip to content

Commit

Permalink
samgozman#30 fix non-alphanumeric lexems replacement with \b
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrigus committed Dec 7, 2016
1 parent 352f98d commit 215ccf2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/yoptascript.js
Expand Up @@ -2440,7 +2440,17 @@ var dictionary = [
];

function escapeRegExp(str) {
return "\\b" + str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + "\\b";
var str = str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');

if (/^\w/.test(str)) {
str = "\\b" + str;
}

if (/\w$/.test(str)) {
str += "\\b";
}

return str;
}

function yoptReplaceAll(str, search, replacement) {
Expand Down

0 comments on commit 215ccf2

Please sign in to comment.