Consolidate a function and fix regex.