Fetch string matching with email

hello frnds

I want to match and fetch the string from the db contents so is there a
method for it.

The contents can be [email protected] or also <a href mailto:[email protected]
from both the things I want to fetch only the email id i.e [email protected]

Can ne one help me out?


Dhaval P.

Hi Dhaval,

data = "you data " (can be [email protected] or

you do this

regex = /[:]?[a-zA-Z0-9][email protected][a-zA-Z0-9]+.[a-zA-Z]{3}

if data =~ regex
puts “matched String:(email): #{$&}”
puts “no match”

$& contains the matched sting, $’ : contains the post string after
match, $`: contains the pre string that precedes your match criteria

P.s: change the regex value to what ever you want as necessary.

On Aug 21, 6:17 pm, Dhaval P. [email protected]

ok thanks but what if I want to use the samething with for loop then
will it work?

thanks a lot

Dhaval P.

I am currently using .match(/\[email protected]\S+.\S+/) but i want to refine
it…for the last string i.e after . i want to restrict the no of char
to max 3 only the others should not be displayed …can ne one tell me
how to do it.


dhaval parikh

.match(/\[email protected]\S+.[a-zA-Z0-9]{3,3}/) (min number of char = 3 and max
number of char = 3)
.match(/\[email protected]\S+.[a-zA-Z0-9]{3}/) (min number of char = 3 and max
number of char = unlimited)
.match(/\[email protected]\S+.[a-zA-Z0-9]{,3}/) (min number of char = 0 and max
number of char = 3)

On Sep 6, 3:31 pm, Dhaval P. [email protected]

I you were not already, I want to make you aware that there are top
level domains with names longer than three characters. “museum” for

Wikipedia has the whole list:

thanks a lot to both of you i modified the code a bit as per your

sure it will work, the value of data variable is going to be what ever
you want

array_of_objects = [“mailto:[email protected]”, “[email protected]”, …]

array_of_objects.delete_if { |data|
!(data =~ regex)

On Aug 22, 4:37 pm, Dhaval P. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs