Skip to content

Commit

Permalink
Write Brief: Add alternative apostrophe char to spelling mistakes reg…
Browse files Browse the repository at this point in the history
…ex (#40395)

* add alternative apostrophe char to regex

* changelog

* also strip apostrophes from the end
  • Loading branch information
dhasilva authored Nov 29, 2024
1 parent 67dd08a commit 8c05e7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Write Brief: Add alternative apostroph char to spelling mistakes regex
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ export default function spellingMistakes( text: string ): Array< HighlightedText
// \p{M} matches any Unicode mark (combining characters)
// The regex has three main parts:
// 1. [@#+$/]{0,1} - Optionally matches a single special character at the start
// 2. [\p{L}\p{M}\p{N}'-]+ - Matches one or more letters, marks, numbers, apostrophes, or hyphens
// 3. (?:\/[\p{L}\p{M}\p{N}'-]+)* - Optionally matches additional parts separated by slashes
const wordRegex = new RegExp( /[@#+$/]{0,1}[\p{L}\p{M}\p{N}'-]+(?:\/[\p{L}\p{M}\p{N}'-]+)*/gu );
// 2. [\p{L}\p{M}\p{N}'’-] - Matches one or more letters, marks, numbers, apostrophes, or hyphens
// 3. (?:\/[\p{L}\p{M}\p{N}'-]+)* - Optionally matches additional parts separated by slashes
const wordRegex = new RegExp( /[@#+$/]{0,1}[\p{L}\p{M}\p{N}'-]+(?:\/[\p{L}\p{M}\p{N}'-]+)*/gu );
const matches = Array.from( text.matchAll( wordRegex ) );

matches.forEach( match => {
Expand All @@ -155,8 +155,8 @@ export default function spellingMistakes( text: string ): Array< HighlightedText
const subWords = word.split( /[-/]/ );

subWords.forEach( subWord => {
// remove single quotes from beginning/end
subWord = subWord.replace( /^'+|'+$/g, '' );
// remove single quotes from beginning/end and apostrophes from the end
subWord = subWord.replace( /^'+|['’]+$/g, '' );

if ( ! spellChecker.correct( subWord ) ) {
const subWordStartIndex = startIndex + word.indexOf( subWord );
Expand Down

0 comments on commit 8c05e7a

Please sign in to comment.