Matthew Moss
10/25/2008 9:51:00 PM
> 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.