I have the following text taken from a email body, I want to save each block into a object, then add into a array. but I am struggle to correctly define the for loop, in another word how to seprate the blocks
Name: Andy
Computer: ABC
IP: 192.168.0.1
Added By: Maria
Timestamp: 2018-03-15 08:45:08 +0000 UTC
Name: Richard
Computer: CDE
IP: 192.168.0.2
Timestamp: 2018-03-15 08:45:08 +0000 UTC
..........more blocks................
In Javascript (Jquery can not be supported)
//I first define a array
var msgs= [];
//then define a object
var msg= {
Name:"",
Computer:"",
IP:50,
TimeStamp: new Date()
};
var reg = (.....);
var result;
//wholeMsgBody is the whole text sample I have provided
while((result = reg.exec(wholeMsgBody)) !== null) {
//assume the block = Name:.... until TimeStamp.....
var userName = block.match(Name:.*); //Andy
var computer = block.match(Computer:.*); //ABC
var ip = block.match(Computer:.*) //192.168.0.1
Var timeStamp = new Date(block.match(Timestamp:.*)) //2018/03/15
msgs.push({"Name":userName, "Computer":computer, "ip":ip, "timeStamp":timeStamp})
}
I am basiclly Struggle to define the reg expression. any help would be much appriciated.