Nice, except it is not removing trailing underscore. Shall we remove the trailing underscore at all?

print preg_replace('/(\W|_)+/', '_', 'A0-_-A-');