I am new to regular expression and i need to extract some data from the following file :
Card number: 604861*********3997, SEQ: 175
Current session ID: 175
21/01/2021 08:46:49 : Selected language : ENG
21/01/2021 08:46:49 : Chip application : NO Active
21/01/2021 09:53:03 : Returned code : 0
21/01/2021 09:53:03 : Pin entered
21/01/2021 09:53:09 : Transaction selected: FastCash 40000 on ATM: Y6652114
21/01/2021 09:53:10 : Returned code : 0
21/01/2021 09:53:13 : FastCash Authorization requested
21/01/2021 09:53:14 : FastCash Authorized
Returned code : 0, STAN: 686817
21/01/2021 09:53:27 : Cash dispensed
21/01/2021 09:53:28 : Card ejected
21/01/2021 09:53:29 : Card taken
21/01/2021 09:53:32 : Dispense details:
->cass 1: 0 x 5000 MGA, cass 2: 4 x 10000 MGA
->cass 3: 0 x 10000 MGA, cass 4: 0 x 20000 MGA
------->Total cash dispensed: 40000 MGA
21/01/2021 09:53:32 : Cash presented
21/01/2021 09:53:32 : Waiting for cash to be taken
21/01/2021 09:53:33 : Cash taken
21/01/2021 09:53:39 : Transaction completed
21/01/2021 09:53:41 : Session terminated
Card number: 604861*********3997, SEQ: 185
Here is the code I tried I used group capture but it does not work for some cases and it works for others, also every time I try to combine these expressions I get a "nothing to repeat error"
const CARD_NUMBER = /number:\s*([\d*]*)/gi;
const TRANSACTION_AMOUNT = /FastCash\s*([\d,.]*)/gi;
const TRANSACTION_CURRENCY = /Total cash dispensed:\s*(\D)*/gi;
const TERMINAL_ID = /ATM:\s*(\w*)/;
const EXTERNAL_STAN = /STAN:\s*(\d*)/i;
const TRANSACTION_DATE = /([ a-zA-Z0-9/:_-]+)? : Session terminated/i;
// or combined
var rx = new RegExp(
"number:s(d+*+d+).*?FastCashs(d+).*?ATM:s(w+).*?STAN:s(d+).*?completed[\r\n]+(.*?)s)",
"gi"
);
var matches = new Array();
while ((match = rx.exec(sample)) !== null) {
matches.push(match);
}
console.log(matches);