【问题标题】:Python: Split a string by a word which contains a substringPython:用包含子字符串的单词拆分字符串
【发布时间】:2023-04-03 13:27:08
【问题描述】:

我有一个字符串text = "Fix me a meeting in 2 days"
我有一些单词列表meetingStrings
"meet"meetingStrings 中。所以,我必须通过会议来拆分文本。

期望的输出:

两天后

meetingStrings = [
    "appointment",
    "meet",
    "interview"
]
text = "Fix me a meeting in 2 days"
for x in meetingStrings:
    if x in text.lower(): 
        txt = text.split(x, 1)[1]
        print(txt)

这给出了输出:

两天后。

【问题讨论】:

    标签:
    python
    regex
    python-3.x
    string
    split