@@ -78,7 +78,7 @@ let DIACRITICS_EXCEPTION_STR; // Lazily initialized, see below.
7878
7979const DIACRITICS_REG_EXP = / \p{ M} + / gu;
8080const SPECIAL_CHARS_REG_EXP =
81- / ( [ . * + ? ^ $ { } ( ) | [ \] \\ ] ) | ( \p{ P} ) | ( \s + ) | ( \p{ M} ) | ( \p{ L} ) / gu;
81+ / ( [ * + ^ $ { } ( ) | [ \] \\ ] ) | ( \p{ P} + ) | ( \s + ) | ( \p{ M} ) | ( \p{ L} ) / gu;
8282const NOT_DIACRITIC_FROM_END_REG_EXP = / ( [ ^ \p{ M} ] ) \p{ M} * $ / u;
8383const NOT_DIACRITIC_FROM_START_REG_EXP = / ^ \p{ M} * ( [ ^ \p{ M} ] ) / u;
8484
@@ -708,6 +708,18 @@ class PDFFindController {
708708 #convertToRegExpString( query , hasDiacritics ) {
709709 const { matchDiacritics } = this . #state;
710710 let isUnicode = false ;
711+ const addExtraWhitespaces = ( original , fixed ) => {
712+ if ( original === query ) {
713+ return fixed ;
714+ }
715+ if ( query . startsWith ( original ) ) {
716+ return `${ fixed } [ ]*` ;
717+ }
718+ if ( query . endsWith ( original ) ) {
719+ return `[ ]*${ fixed } ` ;
720+ }
721+ return `[ ]*${ fixed } [ ]*` ;
722+ } ;
711723 query = query . replaceAll (
712724 SPECIAL_CHARS_REG_EXP ,
713725 (
@@ -723,11 +735,11 @@ class PDFFindController {
723735
724736 if ( p1 ) {
725737 // Escape characters like *+?... to not interfere with regexp syntax.
726- return `[ ]* \\${ p1 } [ ]*` ;
738+ return addExtraWhitespaces ( p1 , ` \\${ p1 } ` ) ;
727739 }
728740 if ( p2 ) {
729- // Allow whitespaces around punctuation signs.
730- return `[ ]* ${ p2 } [ ]*` ;
741+ // Allow whitespaces around group of punctuation signs.
742+ return addExtraWhitespaces ( p2 , p2 . replaceAll ( / [ . ? ] / g , "\\$&" ) ) ;
731743 }
732744 if ( p3 ) {
733745 // Replace spaces by \s+ to be sure to match any spaces.
0 commit comments