gpt4 book ai didi

python正则表达式 "\1"

转载 作者:IT老高 更新时间:2023-10-28 20:44:14 25 4
gpt4 key购买 nike

谁能告诉我以下 Python 正则表达式中的“\1”是什么意思?

re.sub(r'(\b[a-z]+) \1', r'\1', 'cat in the the hat')

最佳答案

\1 等价于 re.search(...).group(1),正则表达式中的第一个括号分隔的表达式。

这也是一个有趣的事实,部分原因是 Python 和其他编程语言中的正则表达式比 required to be by CS theory 慢得多。 .

关于python正则表达式 "\1",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20802056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com