2024-10-03 09:21:10 发布
网友
如何连续重复同一个单词两次或更多次,中间可能有不同的空格
这就是我所尝试的:
e = "bored bored boredbored" if re.search(r"{}\s*s/", e): print("The sequence " + e + " contains the same word written two or more times in a row with possible varying intervening whitespace.")
我认为以下措施会奏效:
re.search(r"(\w+)\s+\1", e)
\w+周围的括号定义了一个组,\1表示“匹配第一个组中的任何内容”
\w+
\1
我认为以下措施会奏效:
\w+
周围的括号定义了一个组,\1
表示“匹配第一个组中的任何内容”相关问题 更多 >
编程相关推荐