result = re.findall(r"(\w{2}).*?(\1)", subject, re.IGNORECASE)
人类可读的
# (\w{2}).*?(\1)
#
# Options: Case insensitive; Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks; Regex syntax only
#
# Match the regex below and capture its match into backreference number 1 «(\w{2})»
# Match a single character that is a “word character” (Unicode; any letter or ideograph, any number, underscore) «\w{2}»
# Exactly 2 times «{2}»
# Match any single character that is NOT a line break character (line feed) «.*?»
# Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
# Match the regex below and capture its match into backreference number 2 «(\1)»
# Match the same text that was most recently matched by capturing group number 1 (case insensitive; fail if the group did not participate in the match so far) «\1»
正则表达式
https://regex101.com/r/yB3nX6/1
视觉化
代码
迭代所有匹配项
^{pr2}$获取字符串
人类可读的
注释
如果您想明确只接受}。在
a-z
字符,可以将\w
换成{相关问题 更多 >
编程相关推荐