Closed ixp-nl closed 6 years ago
Example line from MT940 file :61:1807300730D28,5N132000002018827922//B8G30PGA01UD901N
Correct price: Debit 28,50 Parsed price: Debit 901,00
Problem comes from the regex in parseTransactionPrice in the Engine.php The pattern /^:61:.*[CD]([\d,\.]+)N/i has a .* in it which is greedy, when you add a ? after the .* it becomes non greedy and matches the first [CD]([\d,\.]+)N in the line.
/^:61:.*[CD]([\d,\.]+)N/i
.*
?
[CD]([\d,\.]+)N
Correct regex: /^:61:.*?[CD]([\d,\.]+)N/i
/^:61:.*?[CD]([\d,\.]+)N/i
@ixp-nl thanks. I've updated the regex and added a unittest to confirm (and prevent regressions in the future)
Again, thanks for the heads up.
Example line from MT940 file :61:1807300730D28,5N132000002018827922//B8G30PGA01UD901N
Correct price: Debit 28,50 Parsed price: Debit 901,00
Problem comes from the regex in parseTransactionPrice in the Engine.php The pattern
/^:61:.*[CD]([\d,\.]+)N/i
has a.*
in it which is greedy, when you add a?
after the.*
it becomes non greedy and matches the first[CD]([\d,\.]+)N
in the line.Correct regex:
/^:61:.*?[CD]([\d,\.]+)N/i