Regex doesn't work on empty string. Replace with substr condition.