正则表达式前瞻返回意外结果

问题描述 投票:0回答:0

当我运行这段代码时,我得到了 ['a', 'b', 'c']

的输出
import re 
  
my_txt = "abc"

def LetterCompiler(txt):
    result = re.findall(r'(?=[a-c]).', txt)
    return result

print(LetterCompiler(my_txt))

我想知道为什么第一个元素('a')包含在其中。我认为前瞻只会得到第一个字符之后的字符,因为第一个字符之前没有任何内容。

regex regex-lookarounds
© www.soinside.com 2019 - 2024. All rights reserved.