Copy the last 2-3 digits in an sms.

General discussions about Automagic and automation in general

Moderator: Martin

Post Reply
Adib
Posts: 12
Joined: 08 Mar 2016 06:11

Copy the last 2-3 digits in an sms.

Post by Adib » 09 Mar 2016 23:48

I want to extract 2 string of numbers from an sms, for example.

"0123456789 JANE 50"

"0123456789" is called the MSISDN

"50" is called AMOUNT, may vary from 1-100.

I learnt how to extract MSISDN but i can't figure out how to extract AMOUNT.

Any help is greatly appreciated, Martin. Thanks!

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Copy the last 2-3 digits in an sms.

Post by Martin » 10 Mar 2016 18:52

You can use a regex to extract the 50:

Code: Select all

sms_text = "0123456789 JANE 50";
groups = newList();
matches(sms_text, '.*\\s(\\d+).*', groups);
amount = groups[1];
Regards,
Martin

Post Reply