mardi 3 novembre 2020

Restrict the reoccurance in Pattern Matching

I am trying to do pattern matching which should only accept A-Z,a-z,hypen, apostrophe and should not accept numbers, special characters,space. it worked fine with the below code Pattern pattern = Pattern.compile("[0-9\p{Punct}\s&&[^',-]]");

But it needs to accept hypen,apostrophe only once. but according to the above line code its accepting. Can you help me out how to restrict to accept only once but not more than that. It should throw error of its more than that.

Aucun commentaire:

Enregistrer un commentaire