Home > Software engineering >  SMS - Android - Merchant Name from Transaction
SMS - Android - Merchant Name from Transaction

Time:10-29

I want to get Merchant Name from Bank Transaction SMS. For this I used following regx;

Pattern.compile("(?i)(?:\\sInfo.\\s*)([A-Za-z0-9*]*\\s?-?\\s?[A-Za-z0-9*]*\\s?-?\\.?)");

INR1.00 debited on Credit Card XX9007 on 11-Mar-19.Info:GOOGLE CLOUD.Avbl

and its not working

Then how to fetch GOOGLE CLOUD from above SMS?

CodePudding user response:

Your pattern has more parts than that is necessary to capture the value that you want.

The issue is that there is not space before Info, but the pattern tries to match it with this part (?:\\sInfo.\\s*)

You might also simplify the pattern a bit to:

(?i)\\bInfo:\\s*([A-Za-z0-9] \\s[A-Za-z0-9] )

See a regex demo.

Or broader, capturing any char except a dot using a negated character class:

(?i)\\bInfo:\\s*([^.] )

See another regex demo.

  • Related