Code php:
$CardText = preg_replace_callback('/\<([twubrgx0-9]|hbg)>/i', 'ConvertCastingCost', $CardText);
	$CardText = preg_replace_callback('/\<([twubrgx0-9]|hbg)/i', 'ConvertCastingCost', $CardText);

Basically, there may or may not be a closing > on the tag. Sloppy, I know, but I have to keep this backwards compatible.