Forum: Ruby Extracting information from ""

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
2c2f3ce7125411ff78a1d3e902aa2a4d?d=identicon&s=25 Bob Sanders (adistarmid)
on 2008-10-25 23:44

I'm wondering how you'd extract information from an email address like
"" to get these results from that email:

@player_id = 2222
@game_id = 8888

I'm thinking it's something along the lines of:

email =
@player_id = email.gsub(...)
@game_id = email.gsub(...)

Any ideas what belongs in the gsubs?
A61ecce13ed142622f24a5ca3a123922?d=identicon&s=25 Matthew Moss (Guest)
on 2008-10-25 23:52
(Received via mailing list)
> @game_id = email.gsub(...)
> Any ideas what belongs in the gsubs?

Sounds more like a job for regexp pattern matching:

    @player_id, @game_id = email.match(/.+-(\d+)-(\d
    => ["2222", "8888"]

    => "2222"

    => "8888"

You can get more specific with the regexp pattern; the one above I
just threw together quickly.
2c2f3ce7125411ff78a1d3e902aa2a4d?d=identicon&s=25 Bob Sanders (adistarmid)
on 2008-10-26 00:10
That works perfectly. Thank you, Matthew!!
2ee1a7960cc761a6e92efb5000c0f2c9?d=identicon&s=25 William James (Guest)
on 2008-10-26 01:20
(Received via mailing list)
Bob Sanders wrote:

> ""

C:\>irb --prompt xmp
player,game = "".split(/[-@]/)[1,2]
    ==>["2222", "8888"]
This topic is locked and can not be replied to.