Created
November 6, 2016 14:53
-
-
Save sanchojaf/9bc2de786a1ae19400e01fe7e48884ff to your computer and use it in GitHub Desktop.
Matching IP V4 Address (ruby, regular expressions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IP V4 Address are four decimal numbers separated by periods, | |
# each number ranging from 0 to 255. | |
number = /(\d|[01]?\d\d|2[0-4]\d|25[0-5])/ | |
expression = /^(#{number}\.){3}#{number}$/ | |
sample_text = "10.123.80.202" | |
sample_text =~ expression |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment