📅  最后修改于: 2022-03-11 14:45:55.133000             🧑  作者: Mango
# Limit the maximum number of pattern occurrences to be replaced
# replace three occurrence of space with '-'
target_str = "a b c d e f"
res_str = re.sub(r"\s", "-", target_str, count=3)
print(res_str)
# Output a-b-c-d e f