Skip to content

Instantly share code, notes, and snippets.

@sanchojaf
Created November 6, 2016 14:53
Show Gist options
  • Save sanchojaf/9bc2de786a1ae19400e01fe7e48884ff to your computer and use it in GitHub Desktop.
Save sanchojaf/9bc2de786a1ae19400e01fe7e48884ff to your computer and use it in GitHub Desktop.
Matching IP V4 Address (ruby, regular expressions)
# 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