瀏覽代碼

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 年之前
父節點
當前提交
f14779fcfc
共有 2 個文件被更改,包括 6 次插入2 次删除
  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
 
 		}