Javascript 将regex数据呈现给Jade
因此,在下面的代码中,我将从正则表达式匹配中提取的数据写入控制台。但是,我需要将这些数据呈现到jade文件中,以便上传日志文件的用户可以自己查看匹配。有什么想法或信息网站吗Javascript 将regex数据呈现给Jade,javascript,regex,node.js,pug,Javascript,Regex,Node.js,Pug,因此,在下面的代码中,我将从正则表达式匹配中提取的数据写入控制台。但是,我需要将这些数据呈现到jade文件中,以便上传日志文件的用户可以自己查看匹配。有什么想法或信息网站吗 while ((match = reDiaBtoa.exec(newArray[j])) != null) { if (match.index === reDiaBtoa.lastIndex) { reDiaBtoa.lastIndex++; } if (match[2] === "ERROR") { console.
while ((match = reDiaBtoa.exec(newArray[j])) != null) {
if (match.index === reDiaBtoa.lastIndex) {
reDiaBtoa.lastIndex++;
}
if (match[2] === "ERROR") {
console.log(match[2]);
console.log("Time " + match[1]);
console.log("Thread Name: " + match[3]);
console.log("Source name & line number: " + match[4]);
console.log("Log Message: " + match[5] + '\n');
console.log("-----------------------------------------------------------------" + "\n");
var logs = [new Log(match[1], match[3], match[4], match[5])]
}
}
更新:这就是我到目前为止所尝试的
翡翠档案:
...
form(method="post", action="/upload", enctype="multipart/form-data")
input(type="file", name="logName")
button(type="submit") Upload
h1.
Log List
#logs
for log in logs
include log
在我的index.js文件中使用此代码
/* GET home page. */
router.get('/', function (req, res) {
res.render('fileUpload', { title: 'Building a Log File Viewer' }, {logs: logs});
});
function Log(time, thread, source, mess) {
this.time = time;
this.thread = thread;
this.source = source;
this.mess = mess;
}
但它会导致日志未定义的错误。我假设,因为它不会将匹配项放入日志条目中
res.render('fileUpload', { title: 'Building a Log File Viewer' }, {logs: logs});
应该是
res.render('fileUpload', { title: 'Building a Log File Viewer', logs: logs });
我认为这将使日志成为jade模板中的数组,但我认为您的include日志不会将日志视为变量,它只会尝试包含一个名为log.jade的文件。您可能需要读取javascript代码中的日志文件,以获取所需的字符串数据,然后将其传递给jade以包含在HTML中。将其放入数组,然后传递给jade?谢谢,它一直说日志未定义。我使用include日志来包含名为log.jade的文件,该文件列出了log.thread、log.source、log.mess。我确实使用fileRead读取日志文件,但随后我使用正则表达式解析数据。