Hello,
I’m wondering how you’d extract information from an email address like
“[email protected]” to get these results from that email:
@player_id = 2222
@game_id = 8888
I’m thinking it’s something along the lines of:
email = [email protected]
@player_id = email.gsub(…)
@game_id = email.gsub(…)
Any ideas what belongs in the gsubs?
@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.
That works perfectly. Thank you, Matthew!!
Bob S. wrote:
“[email protected]”
C:>irb --prompt xmp
player,game = “[email protected]”.split(/[-@]/)[1,2]
==>[“2222”, “8888”]
player
==>“2222”
game
==>“8888”