How to find a string inside of a string space insensitive?

This question already has an answer here:

  • Does Python have a string 'contains' substring method? 13 answers

  • 简单:

    string = 'odfsdlkfn dskfThe Moonaosjfsl dflkfn'
    if 'The Moon' in string:
        dosomething
    

    you could use regular expressions:

    import re
    text = "odfsdlkfn dskfThe Moonaosjfsl dflkfn"
    if re.find("The Moon", text):
        ...
    

    and in this case, you could ingore casing with re(pattern, text, re.IGNORECASE) if needed.

    链接地址: http://www.djcxy.com/p/9392.html

    上一篇: CSV中的单词搜索,在一个单元格中有多个单词

    下一篇: 如何找到一个字符串空间内的字符串不敏感?