Eraser morphisms and membership problem in groups and monoids