Characterizing regular languages with polynomial densities