使用NYP作为关键字提取句子

时间:2014-05-15 09:54:54

标签: javascript arrays regex filter

我需要帮助。我已经尝试了几天关于正则表达式的代码,使用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);
            }
        };

1 个答案:

答案 0 :(得分:0)

正则表达式在这里过度杀伤; text.toLowerCase().indexOf('nyp') > -1;怎么样? JSFiddle