The Internet Protocol version 4 (IPv4) is the dominant protocol for routing devices over the internet. IPv4 addresses are usually represented by four 1-byte decimal numbers (0 to 255) separated by three dots.
In this exercise, we are asked to check whether a given string of characters is a valid IPv4 address or not. Leading zeros are allowed, however each byte should only contain at most 3 characters, with no spaces.
For example, the following are valid IPv4 address:
'123.123.123.123'
'0.255.001.010'
But the following are invalid addresses:
'0123.123.123.123'
'123. 23.123.123'
'123.123'
'123,123.123.123'
'abc.123.123.123'
'123.456.789.111'
'i like matlab'
The following restrictions apply:
- The function should only have one (1) line of code, excluding the function start line.
- Semicolons (;) are considered end-of-line characters.
- Please suppress the function end line. Keyword 'end' is not allowed.
- Regular expressions are allowed.
- Only 'pure' matlab functions/commands are allowed (no java, no python).
---------------
NOTE:
This would be the last of my one-line challenges.
Solution Stats
Problem Comments
4 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers8
Suggested Problems
-
Find the numeric mean of the prime numbers in a matrix.
9168 Solvers
-
Remove from a 2-D matrix all the rows that contain at least one element less than or equal to 4
140 Solvers
-
Try 1.5.4: Celsius to Fahrenheit
873 Solvers
-
Mysterious digits operation (easy)
329 Solvers
-
Matlab Basics - Logical Tests I
271 Solvers
More from this Author116
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
> Regular expressions are not allowed.
I don't understand this restriction. This kind of task is exactly what regular expressions are for.
HI Christian,
Regex is now allowed. Thanks.
Ramon, were string operations banned as well (with regexp) initially?
String functions are NOT banned.