Skip to content

Commit

Permalink
Fix #41. Aliases not working
Browse files Browse the repository at this point in the history
  • Loading branch information
about-code committed Dec 4, 2019
1 parent bad8128 commit 4ace562
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/term.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,17 @@ class Term {

function updateRegExp(term) {

const termAndAliases = [...term.aliases, term.term];
let flags = "u";
let regExp = `(${term.term}`;
term.aliases.forEach(alias => regExp += "|" + alias);
let regExp = `(`;

// A shorter term may be a substring of a longer term which causes issues
// when the regExp is used to split a text block (see #41). Thus we sort
// sort by length descending to create a regExp which tests for the longest
// term first.
termAndAliases
.sort((term1, term2) => term2.length - term1.length)
.forEach((alias, idx) => regExp += (idx > 0 ? "|" : "") + alias);
regExp += `)`;

if (term.ignoreCase) {
Expand Down

0 comments on commit 4ace562

Please sign in to comment.