If I want to take
"hi, my name is foo bar"
and split it on "foo"
, and have that split be case insensitive (split on any of "foO"
, "FOO"
, "Foo"
, etc), what should I do? Keep in mind that although I would like to have the split be case insensitive, I also DO want to maintain the case sensitivity of the rest of the string.
So if I have:
test = "hi, my name is foo bar"
print test.split('foo')
print test.upper().split("FOO")
I would get
['hi, my name is ', ' bar']
['HI, MY NAME IS ', ' BAR']
respectively.
But what I want is:
['hi, my name is ', ' bar']
every time. The goal is to maintain the case sensitivity of the original string, except for what I am splitting on.
So if my test string was:
"hI MY NAME iS FoO bar"
my desired result would be:
['hI MY NAME iS ', ' bar']
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…