samedi 14 décembre 2019

How to define a String Pattern in Java with a specific range for the numbers? [duplicate]

This question already has an answer here:

I want to define a String Pattern of the type A.B.C.D where the value of A,B,C and D should be in the range of 0 to 255. The length of A,B,C and D shall be from 1 to 3.

I now defined a pattern but if I test it with 256.255.255.255 it prints out true but It shall print out false because 256>255.

Here is my pattern:

class MyRegex{
     String pattern = "\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}";

}

Aucun commentaire:

Enregistrer un commentaire