railslove / cmxl

your friendly MT940 SWIFT file parser for bank statements
http://railslove.com
MIT License
46 stars 25 forks source link

Statement and sequence numbers aren't correctly parsed when without filling 0 digits #52

Open hapm opened 3 years ago

hapm commented 3 years ago

The current regex to parse the statement and sequence numbers doesn't follow the swift specs as declared here.

The examples :28C:235/1 and :28C:235/1 provided in the spec will not match because the regex expects 5 digits for the statement and 3 to 5 digits for the sequence number. The sequence number should be optional and the regex should allow shorter statement and sequence numbers. I would suggest:

/(?<statement_number>\d{1,5})(?:\/(?<sequence_number>\d{1,5}))?/
bumi commented 3 years ago

thanks for raising this. Could you put your suggestion in a PR with an additional test with these examples? that would be amazing. If it does not break any of the other tests then we can merge and release this.

hapm commented 3 years ago

I'll see if I come to that tomorrow.