Regular expression question?

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

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

Hope that helps.

James Edward Gray II

···

On Feb 17, 2005, at 5:09 PM, Lei Wu wrote:

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?

Lei Wu wrote:

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] - class String - RDoc Documentation
[1] - class MatchData - RDoc Documentation

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.

···

On Fri, 18 Feb 2005 08:09:51 +0900, Lei Wu <marathoner@sina.com> wrote:

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

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

Hi,

···

Am Freitag, 18. Feb 2005, 08:12:49 +0900 schrieb James Edward Gray II:

On Feb 17, 2005, at 5:09 PM, Lei Wu wrote:

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

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

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

Zach Dennis wrote:

Lei Wu wrote:

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?

I think I misunderstood the question, but after rereading Jame's and Bertram's post I think I see what Lei Wu was looking for.

Zach

···

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] - class String - RDoc Documentation
[1] - class MatchData - RDoc Documentation

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.

···

--
Este correo esta libre de virus!

Marcelo (PC) wrote:

  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

Thanks Shanko! Thats what I was looking for

Regards
   Marcelo

···

----- Original Message ----- From: "Shashank Date" <sdate@everestkc.net>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Sent: Thursday, February 17, 2005 4:44 PM
Subject: Re: Installer tutorial

Marcelo (PC) wrote:

  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:
Distributing Ruby Applications - Theory and Practice of Building, Packing and Distributing Ruby Applications

HTH,
-- shanko

--
Este correo esta libre de virus!

--
Este correo esta libre de virus!

Shashank Date wrote:

Marcelo (PC) wrote:

  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.

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

James