[英]split String to list by two words - python
I am trying to split a String into a list every time the word '::' or 'episode' appear.每次出现“::”或“情节”一词时,我都试图将一个字符串拆分为一个列表。 I want to split the list every time one of those words appears but I can only give one word to the method 'split()'.
每次出现其中一个单词时,我都想拆分列表,但我只能给方法“split()”一个单词。
I think this code will help我认为这段代码会有所帮助
import re
delimiters = "::", "episode"
example = "hello:: this episode is my favourite"
regexPattern = '|'.join(map(re.escape, delimiters))
print(re.split(regexPattern, example))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.