Utility Mill


Creates a Regular Expression to Match a Numeric Range


Instructions / Discussion

Have you ever needed a regular expression to match a numeric range? Perhaps you need to find a year range in a document such as 1981-2001? Perhaps you want to add validation to some system that only allows regex?

Well, believe it or not, it's very difficult to write regular expressions to match arbitrary numeric ranges. That's why Jody and I made this utility. It will save you that pain and generate a regular expression to match whatever numeric range you want.

You can test the regular expressions it generates online here.

How it works

It's a giant recursive function that goes through the range of values to find each sub-range that can be covered by one regular expression. Then it stitches those regular expressions together with the '|' symbol to make one giant regular expression to match all the numbers.

Please let me know if you find any cases where it doesn't work.

Utility Mill is another wonderful Blended Technologies project.

copyright, owned and operated by Blended Technologies LLC.

Powered by Python and the ineffable Web.py