[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

regex eating my characters

Junkone

1/18/2008 5:58:00 PM

Hello
I am having trouble with this regex

My pattern is
group 1= any word
Group 2= any word
group 3 = any sentence

irb(main):001:0> pattern= Regexp.new('(\S+)\s+(\S+)(.+)')
=> /(\S+)\s+(\S+)(.+)/
irb(main):002:0> pattern.match("list test")
=> #<MatchData:0x2e8cdc4>
irb(main):003:0> $2
=> "tes"


YOu can see that it just ate the last t from $2. dunnno why.

Regadrs

Seede
2 Answers

Alex LeDonne

1/18/2008 6:05:00 PM

0

On Jan 18, 2008 12:59 PM, Junkone <junkone1@gmail.com> wrote:
> Hello
> I am having trouble with this regex
>
> My pattern is
> group 1= any word
> Group 2= any word
> group 3 = any sentence
>
> irb(main):001:0> pattern= Regexp.new('(\S+)\s+(\S+)(.+)')
> => /(\S+)\s+(\S+)(.+)/
> irb(main):002:0> pattern.match("list test")
> => #<MatchData:0x2e8cdc4>
> irb(main):003:0> $2
> => "tes"
>
>
> YOu can see that it just ate the last t from $2. dunnno why.

Nah, it's in $3... if it wasn't available for your (.+), there
wouldn't be a match. Did you mean (.*) at the end?

-A

Junkone

1/18/2008 7:54:00 PM

0

On Jan 18, 1:04 pm, Alex LeDonne <aledonne.listm...@gmail.com> wrote:
> On Jan 18, 2008 12:59 PM, Junkone <junko...@gmail.com> wrote:
>
>
>
>
>
> > Hello
> > I am having trouble with this regex
>
> > My pattern is
> > group 1= any word
> > Group 2= any word
> > group 3 = any sentence
>
> > irb(main):001:0> pattern= Regexp.new('(\S+)\s+(\S+)(.+)')
> > => /(\S+)\s+(\S+)(.+)/
> > irb(main):002:0> pattern.match("list test")
> > => #<MatchData:0x2e8cdc4>
> > irb(main):003:0> $2
> > => "tes"
>
> > YOu can see that it just ate the last t from $2. dunnno why.
>
> Nah, it's in $3... if it wasn't available for your (.+), there
> wouldn't be a match. Did you mean (.*) at the end?
>
> -A- Hide quoted text -
>
> - Show quoted text -

thanks