[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Regular expression question?

Lei Wu

2/17/2005 11:09:00 PM

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

10 Answers

James Gray

2/17/2005 11:13:00 PM

0

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?

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

Hope that helps.

James Edward Gray II



Zach Dennis

2/17/2005 11:15:00 PM

0

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] - http://www.ruby-doc.org/core/classes/String.ht...
[1] - http://www.ruby-doc.org/core/classes/Matc...


Logan Capaldo

2/17/2005 11:17:00 PM

0

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

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.


Bertram Scharpf

2/18/2005 12:10:00 AM

0

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


Zach Dennis

2/18/2005 12:13:00 AM

0

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] - http://www.ruby-doc.org/core/classes/String.ht...
> [1] - http://www.ruby-doc.org/core/classes/Matc...
>
>
>



Marcelo (PC)

2/18/2005 12:37:00 AM

0

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!



Shashank Date

2/18/2005 12:42:00 AM

0

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

HTH,
-- shanko

Marcelo (PC)

2/18/2005 12:58:00 AM

0

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:
> http://www.erikveen.dds.nl/distributingrubyapplications/...
>
> HTH,
> -- shanko
>
>
> --
> Este correo esta libre de virus!
>



--
Este correo esta libre de virus!



James Britt

2/18/2005 1:49:00 AM

0

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


Lei Wu

2/18/2005 2:07:00 PM

0

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