Search code examples
javaregex-group

Java regex to escape pipe


I am trying to parse account no and balance from bank sms using java regex group. I am able to successfully parse account no but not able to get the balance as it is always getting null value maybe due to pipe

Sms I am trying to parse is :

Balances for Ac XXXXXXXX0000 on 16/12/2020 11:37:14 AM ISTTotal Avbl. Bal: INR|980310.28Avbl. Bal: INR 980310.28Linked FD bal: INR|0.0

Regex I am using is:

Balances for Ac (?groupname.+?) on 16/12/2020 11:37:14 AM ISTTotal Avbl. Bal: INR|980310.28Avbl. Bal: INR (?groupname[0-9.]+)Linked FD bal: INR|0.0

Any help would be highly appreciated!


Solution

    1. Escape the pipe like you probably have already tried using a backslash \\|.
    2. Your problem is with what comes next. It will only match for an amount of 0.0.

    Try this:

    INR (?<groupname>[0-9.]+)Linked FD bal: INR\\|(?<amount>[0-9.]+)