My daughter did that too... from about the same age. Our Pediatrician said toddlers often do that. For our daughter, we found she did it when she was "bored" or it was like a relaxing thing. We simply asked her "why" she does that... and she told us.
In any case, it seems to be a phase they go through. But for us, what we did to prevent it... was to explain to her that LOTS of germs are on the fingernails and fingers/hands... and you can get sick that way and catch colds.... that it's not "sanitary." For our daughter, this REALLY did the trick. She learned about how germs are transmitted, and at the same time, how to keep her hands clean... and out of her mouth. Gradually... she has pretty much stopped. She's 5 years old now.
It may take time. But we found that explaining this to our girl helped. And at the same time, we weren't "fibbing" or bribing her with treats or replacing the "habit" with something else.
Our girl also would bite her nails and sometimes to the nib, and her cuticles would hurt. Well... we explained that it's because she bites her nails and it hurts her. Then we put band-aids on it. She didn't like that it hurt.. .and this also "showed" her that what she is doing is painful. But the explanation about germs and bacteria on fingernails is the method that really worked for us.
Might I add, that my Hubby also sometimes bites his nails... and each time he does this, he catches a cold. He learned his lesson. And, so this was "proof" in the pudding for our girl.
Hope this helps...
~Susan