开发者

how can we use preg_match_all()in RoR

开发者 https://www.devze.com 2023-01-03 06:44 出处:网络
is there any RoR method which can work same as preg_match_all() p开发者_运维知识库hp function?Use scan :

is there any RoR method which can work same as preg_match_all() p开发者_运维知识库hp function?


Use scan :

string = 'joe@example.com; walter@example.org'
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/

0

精彩评论

暂无评论...
验证码 换一张
取 消