+-- A regular expression that matches a non-address character.
+non_addr_char :: String
+non_addr_char = "[^\\.0-9]"
+
+
+-- Add non_addr_chars on either side of the given String. This
+-- prevents (for example) the regex '127.0.0.1' from matching
+-- '127.0.0.100'.
+addr_barrier :: String -> String
+addr_barrier x = non_addr_char ++ x ++ non_addr_char
+
+
+-- The magic happens here. We take a CIDR String as an argument, and
+-- return the equivalent regular expression. We do this as follows:
+--
+-- 1. Compute the minimum possible value of each octet.
+-- 2. Compute the maximum possible value of each octet.
+-- 3. Generate a regex matching every value between those min and
+-- max values.
+-- 4. Join the regexes from step 3 with regexes matching periods.
+-- 5. Stick an address boundary on either side of the result.