Variables in regex


Does anyone know how I can write a regular expression using a variable
in a range?

For example:
string.scan(/(.{1, variable})(?: |$)/).join("\n")

This generates the following error:
warning: regexp has invalid interval
                                        warning: regexp has `}' without

I have seen some postings where RegEx.quote(variable) is used but this
does not seem to work in a range.