I want a Regex that I want to use in Java Pattern annotation to match with a String that contains maximum one dot.
I found a Regex that works outside Java here:
I am not sure why but the Regex doesn't seem to work when passed in the Pattern annotation.
@Pattern(regex = "^[^.]*(?:\\.[^.]*)?$")
private String name;
Nick.Div -- Matches
NickDiv -- Matches
Nick.Div. -- Doesn't Match
Nic.k.Div -- Doesn't Match
Use this pattern:
^first of string
[^.]*a character class which matches zero or more of everything except
\\.matches a dot
$end of string