Regular expression question?

L

Lei Wu

Hi,

I want to translate the following Perl code into Ruby:

@captures = ($text =~ /company=(.+)/g)

Basically, the Perl version uses the g modifier to capture all
occurrence of the matches in () and put them into an array.

How do I do this in Ruby?

Thanks in advance.

Lei
 
J

James Edward Gray II

Hi,

I want to translate the following Perl code into Ruby:

@captures = ($text =~ /company=(.+)/g)

Basically, the Perl version uses the g modifier to capture all
occurrence of the matches in () and put them into an array.

How do I do this in Ruby?

captures = text.scan(/company=(.+)/)

Hope that helps.

James Edward Gray II
 
Z

Zach Dennis

Lei said:
Hi,

I want to translate the following Perl code into Ruby:

@captures = ($text =~ /company=(.+)/g)

Basically, the Perl version uses the g modifier to capture all
occurrence of the matches in () and put them into an array.

How do I do this in Ruby?

match_data = text.match( /company=(.+)/ ) # see [0]

You can then treat your MatchData [1] object like an array and access
matches like:

match_data[0]

HTH,

Zach

[0] - http://www.ruby-doc.org/core/classes/String.html#M001335
[1] - http://www.ruby-doc.org/core/classes/MatchData.html
 
L

Logan Capaldo

Hi,

I want to translate the following Perl code into Ruby:

@captures = ($text =~ /company=(.+)/g)

Basically, the Perl version uses the g modifier to capture all
occurrence of the matches in () and put them into an array.

How do I do this in Ruby?

Thanks in advance.

Lei

Like so:
captures = string.scan(/company=(.+)/)

There will be an extra level of nesting so you may (or may not,
depending on how many groups your capturing) want to #flatten
captures.
 
B

Bertram Scharpf

Hi,

Am Freitag, 18. Feb 2005, 08:12:49 +0900 schrieb James Edward Gray II:
captures = text.scan(/company=(.+)/)

As far as I see, `+' is greedy. Further, you don't need the
grouping. May this is better:

captures = text.scan /company=\S+/

Bertram
 
M

Marcelo (PC)

Hello there!

I'm still new to Ruby and I was wondering if anyone know of a tutorial or
procedure to prepare an installer for my Ruby applicacion. What I mean is a
procedure or steps thay I should follow in order to make a full installer
for my applicacion, that is, install Ruby compiler and all the needed
libraries needed by my application. I think it would be a little troubling
if the regular user need to install the Ruby compiler, FXRuby libraries,
etc. on his/her own.

Thanks

Marcelo Panigua L.
 
S

Shashank Date

Marcelo said:
I'm still new to Ruby and I was wondering if anyone know of a tutorial
or procedure to prepare an installer for my Ruby applicacion. What I
mean is a procedure or steps thay I should follow in order to make a
full installer for my applicacion, that is, install Ruby compiler and
all the needed libraries needed by my application. I think it would be
a little troubling if the regular user need to install the Ruby
compiler, FXRuby libraries, etc. on his/her own.

If you are Windows you should take a look at Erik Veenstra's
RubyScript2exe package.

Read here:
http://www.erikveen.dds.nl/distributingrubyapplications/index.html

HTH,
-- shanko
 
M

Marcelo Paniagua

Thanks Shanko! Thats what I was looking for

Regards
Marcelo



----- Original Message -----
From: "Shashank Date" <[email protected]>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <[email protected]>
Sent: Thursday, February 17, 2005 4:44 PM
Subject: Re: Installer tutorial
 
J

James Britt

Shashank said:
If you are Windows you should take a look at Erik Veenstra's
RubyScript2exe package.

I second that. I was using it earlier today, and it is quite the thing.

James
 
L

Lei Wu

Thank you very much for your help, guys!

I was surprised to see as many as 10 responses to my question.

That's what makes this Ruby newsgroup such a nice place.

Lei
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top