Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > variables in regex

Reply
Thread Tools

variables in regex

 
 
JCYoder@gmail.com
Guest
Posts: n/a
 
      09-02-2005
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.

 
Reply With Quote
 
 
 
 
David A. Black
Guest
Posts: n/a
 
      09-02-2005
Hi --

On Sat, 3 Sep 2005 http://www.velocityreviews.com/forums/(E-Mail Removed) 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
(E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
Put variables into member variables or function variables? tjumail@gmail.com C++ 9 03-23-2008 04:03 PM
Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine? =?Utf-8?B?SmViQnVzaGVsbA==?= ASP .Net 2 10-22-2005 02:43 PM
Java regex imposture re: Perl regex compatibility a_c_Attlee@yahoo.com Java 2 05-06-2005 12:16 AM
perl regex to java regex Rick Venter Java 5 11-06-2003 10:55 AM



Advertisments