views:

22

answers:

1

Hi All is there any RoR method which can work same as preg_match_all() php function?

A: 

Use scan :

string = '[email protected]; [email protected]'
result = string.scan(/([a-z0-9_.-]+)@([a-z0-9-]+)\.[a-z.]+/i)
p result.size
# => 2

p result
# => [["joe", "example"], ["walter", "example"]]

there is a good article here: http://railsforphp.com/2008/01/17/regular-expressions-in-ruby/

Jesse
i want output as ['[email protected]','[email protected]']
ashok