Regex in a rule extracting a value to a new item

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?

Java actually, but the JavaScript one should be close enough.

Use

Bals: \\$([\d]+\.[\d]{2}).*.

Is this bit still valid (the bit in the group)?
[0-9.]+

As it’s currently reading:
Bals: $0 . 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.

Rather than a decimal value.

That won’t work because you are basically saying " any character between 0-9 or any arbitrary character (i.e. the .) one or more times. That basically matches the whole string, as you are finding.

Use the regex I provided which is more constrained (i.e. it only allows one decimal and only two numbers after the decimal).

Ahh think I got it. I altered to
,"Bals: \\$([\\d.]+).*"

the \d was important. And the . should cover the decimal. I need to put some money on that phone now and see if the balance it updated…then I’ll have a scheme for notifying me when this phone (which I use an an sms gateway and is in a cupboard) needs a top up…

hmm I see your reply. So for the following string:
Bals: $0 . 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.

That wouldn’t work as no decimal place.