Skip to content

Instantly share code, notes, and snippets.

@philk
Created May 24, 2012 18:37
Show Gist options
  • Select an option

  • Save philk/2783364 to your computer and use it in GitHub Desktop.

Select an option

Save philk/2783364 to your computer and use it in GitHub Desktop.
Monkeypatch string
class String
def is_valid_ip?
self.match(/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/) ? true : false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment