From: Matthew Moss Date: 2008-10-26T06:51:04+09:00 Subject: Re: Extracting information from "john-2222-8888@domain.com" > I'm wondering how you'd extract information from an email address like > "john-2222-8888@domain.com" to get these results from that email: > > @player_id = 2222 > @game_id = 8888 > > I'm thinking it's something along the lines of: > > email = john-2222-8888@domain.com > @player_id = email.gsub(...) > @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 +)@domain.com/).captures => ["2222", "8888"] @player_id => "2222" @game_id => "8888" You can get more specific with the regexp pattern; the one above I just threw together quickly.