Node.js:正则表达式获取“From:”和“To:” [英] Node.js: Regular Expression To Get "From: " and "To: "
本文介绍了Node.js:正则表达式获取“From:”和“To:”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于此文本文件:
Received: from unknown (HELO aws-bacon-delivery-svc-iad-1007.vdc.g.com) ([10.146.157.151])
by na-mm-outgoing-6102-bacon.iad6.g.com with ESMTP; 12 Apr 2011 14:30:47 +0000
Return-Path: 0000012f4a2a0037-528dbafb-e773-44be-bef5-07d8f63e6aee-000000@email-bounces.g.com
Date: Tue, 12 Apr 2011 14:42:37 +0000
From: xxx@xxx.example.com
To: yyy@yyy.example.com
Message-ID: <0000012f4a2a0037-528dbafb-e773-44be-bef5-07d8f63e6aee-000000@email.g.com>
Subject: test
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
X-AWS-Outgoing: 199.255.192.79
testing123
我想获得每个字段(Return-path,Date,From,To等)以及正文(testing123) 。
I want to get every field (Return-path, Date, From, To, etc.) as well as the body ("testing123).
我尝试使用匹配:
var bodyRegex = /[\n]Subject: (.+)[\n](.+)/
但我得到空值。
推荐答案
试试这个:
代码:
//var rePattern = new RegExp(/^Received:(.*)$/);
var rePattern = new RegExp(/^Subject:(.*)$/);
var arrMatches = strText.match(rePattern);
结果:
arrMatches[0] -> Subject: test
arrMatches[1] -> test
这篇关于Node.js:正则表达式获取“From:”和“To:”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文