Home > Software engineering >  How can I make it so that here \\.(....|..) the points are only numbers [\\.(....|..)0-9]? (Java
How can I make it so that here \\.(....|..) the points are only numbers [\\.(....|..)0-9]? (Java

Time:11-07

I have the regex variable.matches("\.(....|..)"). Now, my String needs to have a dot, and two or four characters after the dot. But my problem is, that I need that the characters are only numbers from 0-9. For example, I need that it only matches when I have for instance:

.12 or .22 or .8389 or.3920 and not .dd or .d93j, so the characters after the dot needs to be numbers, but variable.matches("[\.(....|..)0-9]") doesn't work. How can I fix that?

CodePudding user response:

Try this:

"\\.(\\d{2}|\\d{4})"
  • Related