我有以下字符串:Python的更换有一定的可变部分子
Billy got score of 2 and Tommy got score of 3
我想拆就score of <some number>
让我得到
["Billy got","Tommy got"]
我怎样才能在Python做这种分裂?我试过
input.split("score of \d")
但这不起作用。但是,如果我做
input.split("score of")
然后我得到
["Billy got "," 2 and Tommy got "," 3"]
更新:
感谢您的回答原来的岗位。我有一个后续。
如果我想用score of 2$
替换score of 2
怎么办?这意味着每当我看到score of <some number>
只是后面加一个字符$
参见['re.split'(https://docs.python.org/3/library/re.html#re.split)如果你想与分裂一个正则表达式。 – khelwood