Extracting information from "[email protected]"

B

Bob Sanders

Hello,

I'm wondering how you'd extract information from an email address like
"(e-mail address removed)" to get these results from that email:

@player_id = 2222
@game_id = 8888

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

email = (e-mail address removed)
@player_id = email.gsub(...)
@game_id = email.gsub(...)

Any ideas what belongs in the gsubs?
 
M

Matthew Moss

I'm wondering how you'd extract information from an email address like
"(e-mail address removed)" to get these results from that email:

@player_id = 2222
@game_id = 8888

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

email = (e-mail address removed)
@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.
 
W

William James

Bob said:
"(e-mail address removed)"

C:\>irb --prompt xmp
player,game = "(e-mail address removed)".split(/[-@]/)[1,2]
==>["2222", "8888"]
player
==>"2222"
game
==>"8888"

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top