java - How do I check to see if there are more than 2 of a character in a string sequence? -
in java program have string. want check contents of string , make sure single character not repeated more 2 times in entire string. example, in "abcdefghdid" character 'd' has 3 occurrences, want return error if in string character occurs more 2 times without regard character's positions in string.
i'm not sure how this, should use regex?
you can use regular expression , if matches /(\w).*\1.*\1/
string illegal.
or can split string individual characters , count how many times occur.
Comments
Post a Comment