Extract (parse) amount and description from BIZ (Transaction) sms
Asked Answered
P

6

15

I am doing below steps.

  1. match sms with regex

  2. if contains specified keyword then get values from sms body like amount,description (reason of transaction), Account number(if ATM withdraw),transaction type(debit/credit)

    this regex not matching all kind of bank/transaction sms thus it is not efficient , is there any other way to identify bank message.

example sms :

1) Dear Customer, your Account Number XXXXXX6377 has been credited by Rs 215.000 being DBT/DBTL funds transfer on 19/05/2015 - CENTRAL BANK OF INDIA

2)A/c NN5715 debited for Rs 2000; ATM WDL. A/c Bal(sub to chq realisatn) Rs13286.23 on 24APR 21:19hr. Call 1800226999 to block your card if not used by you.

3) Dear Customer, Your Ac XXXXXXXX5666 is credited with INR8,922.00 on 16 Feb. Info. INF*000080483346*SALARY. Your Net Available Bal is INR 8,922.00.

private static ArrayList<SmsDto> parsevalues(ArrayList<SmsDto> body_val) {
    ArrayList<SmsDto> resSms = new ArrayList<>();
    for (int i = 0; i < body_val.size(); i++) {
        SmsDto smsDto = body_val.get(i);
        Pattern regEx
                = Pattern.compile("(?:inr|rs)+[\\s]*[0-9+[\\,]*+[0-9]*]+[\\.]*[0-9]+");
        // Find instance of pattern matches
        Matcher m = regEx.matcher(smsDto.getBody());
        if (m.find()) {
            try {
                Log.e("amount_value= ", "" + m.group(0));
                String amount = (m.group(0).replaceAll("inr", ""));
                amount = amount.replaceAll("rs", "");
                amount = amount.replaceAll("inr", "");
                amount = amount.replaceAll(" ", "");
                amount = amount.replaceAll(",", "");
                smsDto.setAmount(Double.valueOf(amount));
                if (smsDto.getBody().contains("debited") ||
                        smsDto.getBody().contains("purchasing") || smsDto.getBody().contains("purchase") || smsDto.getBody().contains("dr")) {
                    smsDto.setTransactionType("0");
                } else if (smsDto.getBody().contains("credited") || smsDto.getBody().contains("cr")) {
                    smsDto.setTransactionType("1");
                }
                smsDto.setParsed("1");
                Log.e("matchedValue= ", "" + amount);
                if (!Character.isDigit(smsDto.getSenderid().charAt(0)))
                    resSms.add(smsDto);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            Log.e("No_matchedValue ", "No_matchedValue ");
        }
    }
    return resSms;
}
Partiality answered 26/6, 2015 at 8:9 Comment(0)
F
22

For finding out amount from bank transaction message.

(?i)(?:(?:RS|INR|MRP)\.?\s?)(\d+(:?\,\d+)?(\,\d+)?(\.\d{1,2})?)

For finding out merchant name from bank transaction message.

(?i)(?:\sat\s|in\*)([A-Za-z0-9]*\s?-?\s?[A-Za-z0-9]*\s?-?\.?)

For finding out card name(debit/credit card) from bank transaction message.

(?i)(?:\smade on|ur|made a\s|in\*)([A-Za-z]*\s?-?\s[A-Za-z]*\s?-?\s[A-Za-z]*\s?-?)
Fishtail answered 24/5, 2016 at 9:25 Comment(4)
Its works for me to fetch amount from bank message. But now I want to find name of account from which my amount gets credited/Debited. eg : my message is like "Thank you for using Debit Card ending with 1001 for Rs.2500.00 in MUMBAI at ADITYA BIRLA FASHION on 2017-02-20." Now i want to fetch "ADITYA BIRLA FASHION" from bank messages. so how to do that?Finbur
@priyankakamthe : You can use this pattern for your message : (?i)(?:\sat\s|in|on*)([A-Za-z0-9]*\s?-?\s?[A-Za-z0-9]*\s?-?\.?)Jaquez
@VikalpPatel this regx works for those message which having at or in or on . But what if message contains other than this. Like : "Dear Customer, You have made a Debit Card purchase of INR1,600.00 on 30 Jan. Info.VPS*AGGARWAL SH. "Finbur
@priyankaKamthe were you able to find out a fix which covers all these cases?Dettmer
P
3

In python following Regex can be helpful.

For finding amount in bank messages

[rR][sS]\.?\s[,\d]+\.?\d{0,2}|[iI][nN][rR]\.?\s*[,\d]+\.?\d{0,2}

For finding A/C no

[0-9]*[Xx\*]*[0-9]*[Xx\*]+[0-9]{3,}
Pitts answered 29/11, 2017 at 6:42 Comment(0)
R
2

The following two regular expressions helped in finding amount from most of the bank transactions(HDFC, ICICI, ING, KOTAK, SBI, CANARA, PNB):

[Ii][Nn][Rr](\\s*.\\s*\\d*)
[rR][sS](\\s*.\\s*\\d*)

Please comment if you have figured out much better expressions than the above.

Restless answered 28/8, 2015 at 5:32 Comment(2)
thanks for answer is these regx will gives transaction separate infoPartiality
thanks but I get only first Digit of amount using [Ii][Nn][Rr](\\s*.\\s*\\d*) reguler expression.how can i get all digitsDeel
S
2

Please Check in this link:-https://github.com/vikashstm/transactionsmsfilter Here maximum , banking filter added.

It has also get through message:-

  1. Deducted Amount,
  2. balance message identified and get available message
  3. Account Number
  4. Transaction Mode
  5. Reference Number/transaction Information etc...
Sachiko answered 10/5, 2021 at 5:31 Comment(0)
T
1

To detect any transactional message in android :

"(?=.*[Aa]ccount.*|.*[Aa]/[Cc].*|.*[Aa][Cc][Cc][Tt].*|.*[Cc][Aa][Rr][Dd].*)(?=.*[Cc]redit.*|.*[Dd]ebit.*)(?=.*[Ii][Nn][Rr].*|.*[Rr][Ss].*)"

tested on several bank messages

Tessera answered 3/3, 2018 at 17:21 Comment(2)
This is giving me promotional messages also. Is there any alternative to find out only credit card and debit card transactions?Bohi
try including more words like Transaction,Amount..This regex was working fine for me.Try to figure out why that promotional message is filtering out.Tessera
K
1

Please check https://github.com/minimal-scouser/trny

Usage:


import { getTransactionInfo } from "trny";

const message = "Your a/c XX0413 is debited on 15/12/2020 by INR 3,211.00 towards purchase. Avl Bal: INR 5,603.54.";

const info = getTransactionInfo(message);
 
/* 
info = {     
   account: {
    type: "account",
    no: "0413"
   },
   balance: "5603.54",
   money: "3211.00",
   typeOfTransaction: "debited" 
}
*/

It also has methods like

  1. getAccount
  2. getMoneySpent
  3. getBalance

This needs more testing but see if this solves your problem.

Kelsey answered 20/3, 2021 at 12:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.