Move Regex functions into common code and header