Bladeren bron

Example search engine: Match all words, in any order (#26971)

* match all words, in any order

* docs: match all words, in any order
sunag 1 jaar geleden
bovenliggende
commit
f14779fcfc
2 gewijzigde bestanden met toevoegingen van 6 en 2 verwijderingen
  1. 3 1
      docs/index.html
  2. 3 1
      examples/index.html

+ 3 - 1
docs/index.html

@@ -359,7 +359,9 @@
 
 		function escapeRegExp( string ) {
 
-			return string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847
+			string = string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847
+
+			return '(?=.*' + string.split( ' ' ).join( ')(?=.*' ) + ')'; // match all words, in any order
 
 		}
 

+ 3 - 1
examples/index.html

@@ -253,7 +253,9 @@
 
 		function escapeRegExp( string ) {
 
-			return string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847
+			string = string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847
+
+			return '(?=.*' + string.split( ' ' ).join( ')(?=.*' ) + ')'; // match all words, in any order
 
 		}