Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  97] [ 2]  / answers: 1 / hits: 44679  / 13 Years ago, fri, april 15, 2011, 12:00:00

Given this text file:



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: [email protected]
To: [email protected]
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


I want to get every field (Return-path, Date, From, To, etc.) as well as the body (testing123).



I've tried matching using:



    var bodyRegex = /[n]Subject: (.+)[n](.+)/


but I get empty value.


More From » regex

 Answers
18

Try this:



Code:



//var rePattern = new RegExp(/^Received:(.*)$/);
var rePattern = new RegExp(/^Subject:(.*)$/);

var arrMatches = strText.match(rePattern);


Result:



arrMatches[0] -> Subject: test
arrMatches[1] -> test

[#92710] Thursday, April 14, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alli

Total Points: 409
Total Questions: 101
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
alli questions
Sat, Apr 23, 22, 00:00, 2 Years ago
Mon, May 18, 20, 00:00, 4 Years ago
Tue, Mar 24, 20, 00:00, 4 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
;