如何在 space 不敏感的字符串中查找字符串?
How to find a string inside of a string space insensitive?
例如,如果字符串包含:
odfsdlkfn dskfThe Moonaosjfsl dflkfn
如何检查它是否包含 "The Moon"?
我目前一直在做的是(但不起作用):
if string.find("The Moon")!=-1:
doSomething
有办法吗?
谢谢!
简单:
string = 'odfsdlkfn dskfThe Moonaosjfsl dflkfn'
if 'The Moon' in string:
dosomething
你可以使用正则表达式:
import re
text = "odfsdlkfn dskfThe Moonaosjfsl dflkfn"
if re.find("The Moon", text):
...
在这种情况下,如果需要,您可以使用 re(pattern, text, re.IGNORECASE)
取消大小写。
例如,如果字符串包含:
odfsdlkfn dskfThe Moonaosjfsl dflkfn
如何检查它是否包含 "The Moon"?
我目前一直在做的是(但不起作用):
if string.find("The Moon")!=-1:
doSomething
有办法吗?
谢谢!
简单:
string = 'odfsdlkfn dskfThe Moonaosjfsl dflkfn'
if 'The Moon' in string:
dosomething
你可以使用正则表达式:
import re
text = "odfsdlkfn dskfThe Moonaosjfsl dflkfn"
if re.find("The Moon", text):
...
在这种情况下,如果需要,您可以使用 re(pattern, text, re.IGNORECASE)
取消大小写。