Skip to content

Parser fails when transaction string contains amount without decimal separator #12

@Petur06

Description

@Petur06

Given statement with the following line
:61:2012031203CR20NMSCVS0015060871
the parser throws
System.Data.InvalidExpressionException: '2012031203CR20NMSCVS0015060871'

I narrowed it down to the fact that the amount in this case does not contain the decimal separator.

As seen in the regex, the decimal separator is expected. (?<ammount>\d*[,.]\d{0,2})

var regex = new Regex(@"^(?<valuedate>(?<year>\d{2})(?<month>\d{2})(?<day>\d{2}))(?<entrydate>(?<entrymonth>\d{2})(?<entryday>\d{2}))?(?<creditdebit>C|D|RC|RD)(?<fundscode>[A-z]{0,1}?)(?<ammount>\d*[,.]\d{0,2})(?<transactiontype>[\w\s]{4})(?<reference>[\s\w]{0,16})(?:(?<servicingreference>//[\s\w]{0,16}))*(?<supplementary>\r\n[\s\w]{0,34})*");

In the PR, you can see two changes to the regex:

  1. removed '?' from the 'fundscode' group
  2. added {0,1} to the 'ammount' group

Simply adding {0,1} to the 'ammount' group did not help, I also had to remove the '?' from the 'fundscode' group.

#11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions