Variables in regex

#1

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 escape

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

(David A. Black) #2

Hi --

···

On Sat, 3 Sep 2005 JCYoder@gmail.com wrote:

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 escape

  /.{1,#{variable}}/

David

--
David A. Black
dblack@wobblini.net