Refine variable existence checking and implement a similar method for regex variables