Extract (parse) the amount and description from the Biz (Transaction) SMS

I do below steps.

  • sms match with regular expression

  • if it contains the specified keyword, then it receives values ​​from the sms body, such as amount, description (transaction reason), account number (if ATM is canceled), transaction type (debit / credit)

    this regular expression does not match all types of banking / sms transactions, therefore it is inefficient if there is another way to identify a bank message.

Sms example:

1) Dear customer, your account number XXXXXX6377 was credited to Rs 215,000 , which is a transfer of funds DBT / DBTL 05/19/2015 - CENTRAL BANK OF INDIA

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

3) Dear customer, your Ac XXXXXXXX5666 sent INR8,922.00 February 16 Info. INF * 000080483346 * SALARY. Your network of available backs is 8 922.00 INR.

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; } 
+6
source share
4 answers

To determine the amount from a bank transaction message.

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

To find out the seller’s name from a bank transaction message.

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

To find out the name of the card (debit / credit card) from a 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?-?) 
+9
source

The following two regular expressions helped to find the amount from most banking transactions (HDFC, ICICI, ING, KOTAK, SBI, CANARA, PNB):

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

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

+1
source

In python after regex can be useful.

To find the amount in bank messages

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

To find A / C no

 [0-9]*[Xx\*]*[0-9]*[Xx\*]+[0-9]{3,} 
0
source

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].*)" 

checked for several bank messages

0
source

Source: https://habr.com/ru/post/989792/


All Articles