以下是Python和R
中完全相同的正则表达式模式匹配的两个示例的Python:
In[1]: import re
In[2]: reg = re.compile("oa")
In[3]: files = [".vim", ".jupyter", "Downloads", "Documents", ".bashrc", "R", "Python"]
In[4]: [x for x in files if reg.match(x)]
Out[4]: []
R:
> files <- c(".vim", ".jupyter", "Downloads", "Documents", ".bashrc", "R", "Python")
> grep("oa", files, value = TRUE)
[1] "Downloads"
为什么Python正则表达式不会返回任何内容?