I am working with the Amazon Mechanical Turk API and it will only allow me to use regular expressions to filter a field of data.
I would like to input an integer range to a function, such as 256-311 or 45-1233, and return a regex that would match only that range.
A regex matching 256-321 would be:
b((25[6-9])|(2[6-9][0-9])|(3[0-1][0-9])|(32[0-1]))b
That part is fairly easy, but I am having trouble with the loop to create this regex.
I am trying to build a function defined like this:
function getRangeRegex( int fromInt, int toInt)
{
return regexString;
}
I looked all over the web and I am surprised that it doesn't look like anyone has solved this in the past. It is a difficult problem...
Thanks for your time.
Here's a quick hack:
which produces:
Not properly tested, use at your own risk!
And yes, the generated regex could be written more compact in many cases, but I leave that as an exercise for the reader :)