Using Regex, I want to match a sequence of words entirely in Python. Statically it is possible, but I am unaware about the dynamic way of matching.
Static method
import re
print(re.search(r'\bsmaller than or equal\b', 'When the loan amount is smaller than or equal to 50000'))
I am trying to do the same thing dynamically, by matching the entire sequence with a list.
Here is the code snippet below:
import re
list_less_than_or_equal = ['less than or equal', 'lesser than or equal', 'lower than or equal', 'smaller than or equal','less than or equals', 'lesser than or equals', 'lower than or equals', 'smaller than or equals', 'less than equal', 'lesser than equal', 'higher than equal','less than equals', 'lesser than equals', 'higher than equals']
for word in list_less_than_or_equal:
print(re.search(r'\b'+word+'\b', 'When the loan amount is smaller than or equal to 50000'))
It prints None
as the output.
How to match the entire sequence of words dynamically?