Suppose there is a key word(password)'rain'. The program must be executed only if 75% of characters in a row(!) of the word, provided by user, are equal to the key word:
Here is my regex code:
key = 'rain'
l_word = int(len(key) *3 /4)
my_regex = r'^[a-z0-9_]*' + '[' + key + ']'+'{' + str(l_word) + ',}' + '[a-z0-9_]*$'
bool(re.match(my_regex,'air'))
where l_word
is length of 75% of the key word. But in my_regex there is a problematic place: namely '[' + key + ']'
, because it matches any combination of the key word(in my case it's "rain"), but not in a row. For example "air" shouldn't work, but "12Qain" should.
How can I fix that?