I think this should be ```#<!-- ((ELSE)?IF)((.*)[\s][\$|\.|!]([^\s]+)(.*))-->#```

And then also ```$inner``` above would need to be ```$matches[3]``` instead of ```$matches[2]```