# Regex eating my characters

**URL:** <https://www.ruby-forum.com/t/regex-eating-my-characters/126496>\
**Category:** Ruby\
**Created:** [January 18, 2008, 7:01pm UTC](https://www.ruby-forum.com/t/regex-eating-my-characters/126496 "2008-01-18T19:01:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [January 18, 2008, 7:01pm UTC](https://www.ruby-forum.com/t/regex-eating-my-characters/126496/1 "2008-01-18T19:01:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [January 18, 2008, 7:05pm UTC](https://www.ruby-forum.com/t/regex-eating-my-characters/126496/2 "2008-01-18T19:05:22Z")

</div>

On Jan 18, 2008 12:59 PM, Junkone [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [January 18, 2008, 8:56pm UTC](https://www.ruby-forum.com/t/regex-eating-my-characters/126496/3 "2008-01-18T20:56:20Z")

</div>

On Jan 18, 1:04 pm, Alex LeDonne [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > group 1= any word  
> > 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
