所以我匹配(含实物捐助者的帮助下对堆栈溢出)的项目数:在使用变量REG-EX
User Number 1 will probably like movie ID: RecommendedItem[item:557, value:7.32173]the most!
现在我想从另一个文本文件中提取相应的名称使用项目编号。它的内容如下:
557::Voyage to the Bottom of the Sea (1961)::Adventure|Sci-Fi
由于某种原因,我只是在终端上提出'无'。找不到匹配项。
myfile = open('result.txt', 'r')
myfile2 = open('movies.txt', 'r')
content = myfile2.read()
for line in myfile:
m = re.search(r'(?<=RecommendedItem\[item:)(\d+)',line)
n = re.search(r'(?<=^'+m.group(0)+'\:\:)(\w+)',content)
print n
我不知道如果我能在后面的断言来看看使用变量.. 真的很感激我得到这里的帮助!
编辑:原来唯一的问题是第二个正则表达式中不需要的脱字符号。
在这里工作(CPython的2.6.2),您使用的是什么版本? 'python example.py Voyage' – AlessandroEmm 2013-05-01 09:09:20
我有Python 2.7.2 ... – Siddhartha 2013-05-01 09:15:08
检查你的输入。您的代码适用于我([Ideone示例](http://ideone.com/mD87Gp))。 – soon 2013-05-01 09:15:58