21. Java Regex - String | Java | Hackerrank

preview_player
Показать описание
Problem Statement :
Write a class called MyRegex which will contain a string pattern. You need to write a regular expression and assign it to the pattern such that it can be used to validate an IP address.

Рекомендации по теме
Комментарии
Автор

the solution is
class MyRegex {
String num =
String pattern = num+'.'num+'.'num+'.'num; }
Explanation as
Targets
1----> IP address should be 0-255;

2----> it should contain only digits;

3----> should not exceed 3 digit number i.e (255);

Approach:

1--> it can contain single digit i.e ([0-9]);

2--> It can contain two digits i.e ([0-9][0-9]);

3--> Range is (099 to 199)i.e((0|1)[0-9][0-9]);

4--> range is (200 - 249) i.e (2[0-9][0-9]) ;

5--> range is (250-255) i.e (25[0-5]);
Total :


chiragsharma
Автор

jo samjhana tha vo copy paste mar kr run kr dia, kha se aa jate h ase log....!

gauravkhubchandani
Автор

Bro you failed to explain the regular expression

ytuser
Автор

Muito bom, estou com uma duvida quando se uma vírgula, se eu tiver um valor com, (vírgula) exemplo 124, 56 como ficaria?

rubenalbertassi
Автор

can explain about the regular expression you used in your code to solve this problem

pradiptachatterjee