continuing

This commit is contained in:
frankknoll
2023-04-03 01:10:44 +02:00
parent 2ccef0b33d
commit 78c45bc813
11 changed files with 8779 additions and 0 deletions

19
src/SmartRegexpFactory.py Normal file
View File

@@ -0,0 +1,19 @@
import re
# adapted from function _fnFilterCreateSearch() defined in https://github.com/DataTables/DataTablesSrc/blob/master/js/core/core.filter.js
class SmartRegexpFactory:
def createSmartRegexp(self, searchTerm):
return re.compile(
rf'^{self.assertContainsWords(self.getWords(searchTerm))}.*$',
flags=re.IGNORECASE)
def getWords(self, searchTerm):
return [re.escape(word) for word in re.split(r'\s+', searchTerm)]
def assertContainsWords(self, words):
return ''.join([self.assertContainsWord(word) for word in words])
def assertContainsWord(self, word):
return f'(?=.*?{word})'