【发布时间】:2014-07-03 16:50:40
【问题描述】:
我需要这方面的帮助。几天来,我一直在尝试有关正则表达式以使用 NYP 作为关键字来提取句子的代码,结果并不是我所期望的。我需要的是其中包含 NYP 的句子,请为我的项目提供帮助。 !我的代码在评论框中。
//readline
var fs = require('fs'),
readline = require('readline');
//reading the file
var rd = readline.createInterface({
input: fs.createReadStream('nyptweets38.out'),
output: process.stdout,
terminal: false
});
//because its a JSON file so I just want the necessary information. the date and text
rd.on('line', function (line) {
/*console.log(JSON.parse(line));
create JSON object */
var TEMP = JSON.parse(line);
console.log(TEMP.created_at + " : (" + TEMP.text + ")\n\n\n");
})
//here is where the filter starts
if (!Array.prototype.filter) {
Array.prototype.filter = function (fun /*, thisp*/ ) {
var len = this.length;
if (typeof fun != "function") throw new TypeError();
var res = new Array();
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (filtered.length > 0) {
console.log(filtered);
return (filtered.length != -1);
}
};
【问题讨论】:
-
if (filtered.length > 0){ console.log(filtered); return (filtered.length != -1); }};
-
请将您的代码编辑到问题中。
-
@AndrewWhitaker 我将代码粘贴在评论框中
-
var fs = require('fs'), readline = require('readline'); var rd = readline.createInterface({ input: fs.createReadStream('nyptweets38.out'), output: process.stdout, terminal: false });
-
rd.on('line', function(line) { /*console.log(JSON.parse(line)); / / 创建 JSON 对象 */ var TEMP = JSON.parse(line); console.log(TEMP.created_at + " : (" + TEMP.text + ")\n\n\n"); })
标签: javascript arrays regex filter