I have the following string in an item:
Bals: $1.45 . See 2dm.co.nz/y2d for all bals and exp dates. Our $19 Carryover Combo is loaded with 1.25GB of data. Text buy 19Carry to 233. Valid for 1 Month, auto renews. NZ Data use only.
I’ve worked out the following regex to get the balance out:
Bals: \$\b(?'balance'[0-9.]+)
Here’s the rule that I’ve written - you can see I’ve played with the rule a little as the rule language doesn’t like some of the \ $ type characters. The item smsgateway_message_body.state contains the string as above:
rule "SMS Gateway get balance"
when
Item smsgateway_message_body received update
or Item sms_check changed
then
logInfo("SMSGateway Get Balance","Command Called")
if (smsgateway_message_body.state != NULL)
{
//Bals: \$\b(?'balance'[0-9.]+)
logInfo("SMSGateway Get Balance","Trying to extract values from : " + smsgateway_message_body.state.toString())
val msg_box = transform("REGEX",".*\\$?balance=([0-9.]+)",smsgateway_message_body.state.toString())
logInfo("SMSGateway Get Balance","Value extracted: " + msg_box)
smsgateway_balance.postUpdate(Float::parseFloat(msg_box))
} else
logInfo("SMSGateway Get Balance","Empty State")
end
Mostly I’m getting null into msg_box variable. I constructed the regex on https://regex101.com/ using the pcre, php flavour, not knowing what we’re using here. Probably javascript right?