Quantcast
Channel: How do I do a case-insensitive string comparison? - Stack Overflow
Viewing all articles
Browse latest Browse all 16

Answer by Luciano Narimatsu de Faria for How do I do a case-insensitive string comparison?

$
0
0
from re import search, IGNORECASEdef is_string_match(word1, word2):    #  Case insensitively function that checks if two words are the same    # word1: string    # word2: string | list    # if the word1 is in a list of words    if isinstance(word2, list):        for word in word2:            if search(rf'\b{word1}\b', word, IGNORECASE):                return True        return False    # if the word1 is same as word2    if search(rf'\b{word1}\b', word2, IGNORECASE):        return True    return False

is_match_word = is_string_match("Hello", "hELLO") True

is_match_word = is_string_match("Hello", ["Bye", "hELLO", "@vagavela"])True

is_match_word = is_string_match("Hello", "Bye")False

Viewing all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>