Skip to content

Commit bd97a20

Browse files
authored
Done using regex
1 parent a08f186 commit bd97a20

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎Validate IP address‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
string validIPAddress(string IP)
4+
{
5+
regex v4("(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])");
6+
7+
// regex v4("(([0-9] |[1-9][0-9]| 1[0-9][0-9] | 2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])");
8+
9+
if(regex_match(IP,v4)==true)
10+
return "IPv4";
11+
12+
regex ipv6("((([0-9a-fA-F]){1,4})\\:){7}(([0-9a-fA-F]){1,4})");
13+
14+
if(regex_match(IP,ipv6))
15+
return "IPv6";
16+
17+
return "Neither";
18+
}
19+
};

0 commit comments

Comments
 (0)