set_facts with if-else clause, also check if the var contains digits?

Im trying to set a variable based on below condition where templname is an external variable with below options

ansible-playbook -i hosts -e “templname=CTrl03_kerbs_09”

OR

ansible-playbook -i hosts -e “templname=CTrl05”

set_fact:
dbn: "{{ CTrl03_kerbs_09 | lower }}
dbnum: “{ % ‘prefix-’ + templname.split(‘')[-1] if '’ in templname else ‘prefix’ %}” ##if templname contains “_” then dbnum should append “prefix-” to the last digit of templname i.e I want “prefix-9”

I want vars set like below:

dbn = ctrl03_kerbs_09
dbnum = prefix-9

dbn = ctrl05

dbnum = prefix

But this doesngt seem to work? Any problem in syntax? I get syntax error…

Also is there a ansible way to check if the string(templname) contains digits??