Remove global variable and fix regex support