Python和R之间的正则表达式差异

时间:2016-05-13 14:29:25

标签: python regex r

以下是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正则表达式不会返回任何内容?

0 个答案:

没有答案