Skip to content

Instantly share code, notes, and snippets.

@MakawaMT
Created October 17, 2019 13:33
Show Gist options
  • Save MakawaMT/a318a3c681d5ff69fa6418cfd8961ae6 to your computer and use it in GitHub Desktop.
Save MakawaMT/a318a3c681d5ff69fa6418cfd8961ae6 to your computer and use it in GitHub Desktop.
Contains regular expressions for SMSes returned when payment is done using the mobile money/bank providers. Regex can be tested at Regex planet https://www.regexplanet.com/ . The REGEX contains named groups which can help you extract particular information for that transaction which can be used for accountability and confirmation
/*
* Copyright (c) 2019 Lomaku Technologies.
* All Rights Reserved.
* 40 Estate Road, Angelo Goveya, Limbe.
* +265 999 388 747
* https://github.com/LomakuIT
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
/* @author: github.com/MakawaMT */
public static final String KEY_PROVIDER_MO_626_SMS = "626626";
public static final String KEY_PROVIDER_AIRTEL_MONEY_SMS = "AirtelMoney";
public static final String KEY_PROVIDER_TNM_MPAMBA_SMS = "MPAMBA";
public static final String KEY_PROVIDER_FDH_SMS = "FDHAlert";
public static final String REGEX_MPAMBA = "[A-Za-z]{5}[\s]*[A-Za-z]{4}[\s]*[A-Za-z]{2}[\s]*(?<account>[0-9]{10})[\s]*(?<firstname>[A-Za-z]{1,15})[\s]*(?<surname>[A-Za-z]{1,15})[\s]*[A-Za-z]{2}[\s]*(?<day>[0-9\\/]{3})(?<month>[0-9\\/]{3})(?<year>[0-9]{4})[\s]*(?<hour>[0-9\\:]{3})(?<minute>[0-9\\:]{3})(?<second>[0-9\\.]{3})[\s]*Amount: (?<amount>[0-9\,\.]+)[\\s]*MWK[\s]*Fee: (?<fee>[0-9\,\.]+)MWK[\s]*Ref: (?<reference>[A-Z0-9]{10})[\s]*Bal: (?<balance>[0-9\,\.]+)MWK[\s]*";
public static final String REGEX_AIRTEL = ".*money[\s]*transfer[\s]*to[\s]*(?<account>[0-9]+)[\s\,]*(?<name>[A-Za-z\s]+)[\s]+is[\s]*successful,[\s]*Trans[\s]*Id:[\s]*(?<reference>[\w\.]+)[\,]+[\s]*Trans[\s]*Amt:[\s]*MK[\s]*(?<amount>[0-9\.\,]+)[\s]+.*available[\s]*balan[c]+e[\s]*MK[\s]*(?<balance>[0-9\,\.]+).*";
public static final String REGEX_MO626 = ".*[\,\s]*Acc:[\s]*(?<sender>[0-9]+)[\s]*got[\s]*a[\s]*[A-Za-z]+[\s]*[A-Za-z]+[\s]*by[\s]*[A-Za-z0-9]+[\s]*of[\s]*MWK(?<amount>[0-9.]+)DR[\s]*To:[\s]*(?<account>[0-9]+)[\s]*Desc:[\s]*(?<ticket>[A-Z0-9]+).[\s]*Date:[\s]*.*[\s]*Ref:[\s]*(?<reference>[A-Z0-9\\]+).*";
public static final String REGEX_FDH = ".*--[\s]*FDH[\s]*BANK[\s]*--[\s]*Txn[\s]*Alert:[\s]*(?<account>[0-9]+)[\s]*Amount:[\s]*MWK(?<amount>[0-9.v ]+)DR[\s]*on:[\s]*.*[\s]*Txn[\s]*Narr:[\s]*(?<reference>[a-zA-Z0-9\s]+)[\s]*Avail[\s]Bal:[\s]*MWK(?<balance>[0-9.]+).*";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment