我有一个很大的文本文件,我从中提取URL。如果我运行:为什么节点不能处理这个正则表达式,但Python可以?
import re
with open ('file.in', 'r') as fh:
for match in re.findall(r'http://matchthis\.com', fh.read()):
print match
它运行在一秒钟左右的用户时间,并得到我想要的网址,但如果我运行这些:
var regex = /http:\/\/matchthis\.com/g;
fs.readFile('file.in', 'ascii', function(err, data) {
while(match = regex.exec(data))
console.log(match);
});
OR
fs.readFile('file.in', 'ascii', function(err, data) {
var matches = data.match(/http:\/\/matchthis\.com/g);
for (var i = 0; i < matches.length; ++i) {
console.log(matches[i]);
}
});
我得到:
FATAL ERROR: CALL_AND_RETRY_0 Allocation failed - process out of memory
发生了什么事与node.js
正则表达式引擎?有什么办法可以修改东西,使他们在node
中工作?
编辑:误差似乎是fs
中心因为这也产生错误:
fs.readFile('file.in', 'ascii', function(err, data) {
});
file.in
约为800MB。
'file.in'里有什么?你能做出一个可重复的例子吗?另外,'http:// matchthis.com'没有正确转义。你需要逃避这段时间。 – Blender
@Blender固定了'\ .'我错过了,因为我输入了问题。 'file.in'是1400000行ascii文本,其中包含各种文本片段中的URL。 – bqui56
@Blender不应该在Python中固定点吗? – thefourtheye