---
title: "Discussion on \"IP Validation Algorithm in Ruby\" | Hashnode"
description: "Discussion on \"IP Validation Algorithm in Ruby\". Master Ruby IP validation using this Medium LeetCode guide, covering IP addresses, string manipulation, and efficient IPv4/IPv6 validation"
url: "https://hashnode.com/posts/ip-validation-algorithm-in-ruby/647f6dec9e9b305b42a394fa"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [IP Validation Algorithm in Ruby](https://blog.austn.net/ip-validation-algorithm-in-ruby?utm_source=hashnode&utm_medium=feed)

Master Ruby IP validation using this Medium LeetCode guide, covering IP addresses, string manipulation, and efficient IPv4/IPv6 validation

Jun 6, 2023 · 4 min read · blog.austn.net  
Read the article

-   [#ruby](https://hashnode.com/tag/ruby)
-   [#algorithms](https://hashnode.com/tag/algorithms)
-   [#data-structures](https://hashnode.com/tag/data-structures)

## Written by

[Austin](https://hashnode.com/@austn)

@austn

  
[View profile](https://hashnode.com/@austn)

Software Engineer

Professional software engineer working at CoverMyMeds, an enterprise healthtech firm that ensures patients get access to the medication they need. Primarily focused on backend and systems design through Ruby and Elixir, but experienced with JavaScript and all things frontend Interested in learning and teaching the craft of software; technical or otherwise Join me as I innovate by iterating!

## Responses 1

Markdown supported · ⌘↵ to post

[yetanothertroll](https://hashnode.com/@yetanothertroll)

[Jun 7, 2023](https://hashnode.com/posts/ip-validation-algorithm-in-ruby/647f6dec9e9b305b42a394fa/comment/647fd86b837566372d406151)

What's wrong with regex? The trick is to break it down into components that you can read without a brain double panic. A little string catenation at run time won't hurt, I promise

[forums.craigslist.org](https://forums.craigslist.org/?ID=327033743)

Yeah, converting that to OG line numbered BASIC isn't happening anytime soon 😂

Edit: Actually, those regexps match up pretty closely to how I'd approach the problem in old BASIC, even if I didn't have anything like InStr or IndexOf and could examine a string only one character at a time in a For loop. It might look a bit like a state machine or DFA

[yetanothertroll](https://hashnode.com/@yetanothertroll)

[Jun 14, 2023](https://hashnode.com/posts/ip-validation-algorithm-in-ruby/647f6dec9e9b305b42a394fa/comment/647fd86b837566372d406151#reply-648913f20a62399c9d69f96a)

[Austin](https://hashnode.com/@austn) The trick is, how do the .\* know when to stop?

Or even "a\*.a" when given "aaaa"

[yetanothertroll](https://hashnode.com/@yetanothertroll)

[Jun 28, 2023](https://hashnode.com/posts/ip-validation-algorithm-in-ruby/647f6dec9e9b305b42a394fa/comment/647fd86b837566372d406151#reply-649bb39fb4f39088739254c6)

[Austin](https://hashnode.com/@austn) I'm running into some not-fun parts now. Constructing the NFA isn't hard, but after that I'm between a rock and a hard spot. Running the equivalent DFA on the (potentially very large) input string is fast, but if the NFA has n states, the DFA could have up to 2ⁿ. Oof. Or you could run the NFA directly, but it could be in all n states for each character in the input string. n\*m vs 2ⁿ, ouch

[yetanothertroll](https://hashnode.com/@yetanothertroll)

[Jun 28, 2023](https://hashnode.com/posts/ip-validation-algorithm-in-ruby/647f6dec9e9b305b42a394fa/comment/647fd86b837566372d406151#reply-649bb5403f5eb98a5001e2fc)

[Austin](https://hashnode.com/@austn) I'm running into some not-fun parts now. Constructing the NFA isn't hard, but after that I'm between a rock and a hard spot. Running the equivalent DFA on the (potentially very large) input string is fast, but if the NFA has n states, the DFA could have up to 2ⁿ. Oof. Or you could run the NFA directly, but it could be in all n states for each character in the input string. n\*m vs 2ⁿ, eek!
