So, I am working on a program in which I need to check if a string has more than one dot. I went and looked at the documentation for regex
and found this:
X{n,m}? X, at least n but not more than m times
Following that logic I tried this:
mString = "He9.lo,"
if (myString.matches(".{1,2}?")){
System.out.print("it works");
}
But that does not works (It does not gives any error, it just wont do what is inside the if
). I think the problem is that is thinking that the dot means something else. I also looked at this question: regex but is for php and I don't know how to apply that to java.
EDIT: Basically I want to know if a string contains more than one dot, for example:
He......lo (True, contains more than one), hel.llo (False, contains one), ..hell.o (True Contains more than one).
Any help would be appreciated.