Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I make it so that here \\.(….|..) the points are only numbers [\\.(….|..)0-9]? (Java) Regex, matches?

have 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 its only match 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]") dont work, how we could fix that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try this:

"\\.(\\d{2}|\\d{4})"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading