---
title: "Comment by yetanothertroll on \"IP Validation Algorithm in Ruby\" | Hashnode"
description: "What&#39;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 tim"
url: "https://hashnode.com/posts/ip-validation-algorithm-in-ruby/647f6dec9e9b305b42a394fa/comment/647fd86b837566372d406151"
---

[Discussion](https://hashnode.com/posts/ip-validation-algorithm-in-ruby/647f6dec9e9b305b42a394fa)

Comment [IP Validation Algorithm in Ruby](https://hashnode.com/posts/ip-validation-algorithm-in-ruby/647f6dec9e9b305b42a394fa)

[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

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

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

Hahaha I felt like it would've made it 10x harder to follow the logic of this post if it needed to also be a RegEx introducer. I'm not personally opposed to using it as long as you understand what you're matching for and how to modify it in case that pattern changes in the future

I'd actually love to dive further into regex myself so maybe that could be a fun future post!

With solving confirm-a-pattern-type problems in BASIC, is using regex super common? I've only ever _had_ to use it a handful of times in ruby/js algos, but that may be because I am spoiled by these languages' built in methods/helpers/etc

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

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

[Austin](https://hashnode.com/@austn) That's actually the first time I've used regex in quite a while. And yeah, don't get too clever, because you'll need to be at least twice as clever to fix or change it six months from now 😂 Most dialects don't support regex, even the one I usually use, X11 BASIC, doesn't support it in the Windows version. I suppose there's always DIY, like this for PC DOS QuickBasic,

[tapatalk.com/groups/qbasic/regular-expressions-qb…](https://www.tapatalk.com/groups/qbasic/regular-expressions-qbasic-t34756.html)

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

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

[Austin](https://hashnode.com/@austn) Oh here we go 😁

[leetcode.com/problems/regular-expression-matching…](https://leetcode.com/problems/regular-expression-matching/description/)

Consider the pattern, ".\*.x.\*."

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

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

[yetanothertroll](https://hashnode.com/@yetanothertroll) oooo this one looks fun

[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!
