variables in regex

J

JCYoder

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.
 
D

David A. Black

Hi --

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top