Generate Regex Patterns for Ranges Like a Boss!

Every now and then I have to write regex — validation, parsing or whatever the reason is, I have to do it.

Recently I had to write a regex for capturing numerical range between 8000 and 9000 and I stumbled upon the tool called rgxg. Official description says that rgxg is

useful to generate (extended) regular expressions to match for instance a specific number range (e.g. 0 to 31 or 00 to FF) or all addresses of a CIDR block (e.g. or 2001:db8:aaaa::/64).

Installation and usage

Ubuntu: sudo apt-get install rgxg (No shit, Sherlock)

For the range I mentioned above, I executed:

$ rgxg range 8000 9999 [89][0-9]{3}

Pretty cool, right?

You can generate other useful regex ranges like IP addresses range:

$ rgxg cidr 192\.168\.0\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])

Read more about the rgxg tool and possible usages on

Originally published at on March 26, 2016.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.