Skip to content

Commit

Permalink
fix: Correctly handle !, ?, and : around the words
Browse files Browse the repository at this point in the history
Fixes #76
  • Loading branch information
sapegin committed Jun 21, 2024
1 parent 76ad536 commit 5b5165a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function readTermsFile(filepath) {
* @param {string} pattern
*/
function getExactMatchRegExp(pattern) {
const punctuation = '[\\.,;\'")]';
const punctuation = '[\\.,;:!?\'")]';
return new RegExp(
// 1. Beginning of the string, or any character that isn't "-" or alphanumeric
// 2. Exact match of the pattern
Expand Down
3 changes: 3 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ describe('getMultipleWordRegExp', () => {
['Bad "Javascript" is it bad?'],
["Bad 'Javascript' is it bad?"],
['Bad "Javascript", is it bad?'],
['Bad Javascript: is this true?'],
['Bad Javascript!'],
['Bad Javascript?'],
])('should match a pattern regardless of punctuation: %s', string => {
const result = getMultipleWordRegExp(variants).exec(string);
expect(result).toBeTruthy();
Expand Down

0 comments on commit 5b5165a

Please sign in to comment.