Split by a word (case insensitive)

后端 未结 3 1499
一向
一向 2020-12-11 15:34

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

3条回答
  •  被撕碎了的回忆
    2020-12-11 16:19

    You can use the re.split function with the re.IGNORECASE flag (or re.I for short):

    >>> import re
    >>> test = "hI MY NAME iS FoO bar"
    >>> re.split("foo", test, flags=re.IGNORECASE)
    ['hI MY NAME iS ', ' bar']
    >>>
    

提交回复
热议问题