小编T0n*_*rdi的帖子

使用正则表达式进行Ruby Email验证

我有一大堆我正在浏览的电子邮件.很多电子邮件都有拼写错误.我正在尝试构建一个检查有效电子邮件的字符串.

这就是我对正则表达式的看法.

def is_a_valid_email?(email)
  (email =~ /^(([A-Za-z0-9]*\.+*_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\+)|([A-Za-z0-9]+\+))*[A-Z??a-z0-9]+@{1}((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,4}$/i)
end
Run Code Online (Sandbox Code Playgroud)

如果电子邮件为下划线且只有一个句点,则会通过.我有很多电子邮件,名称本身有一个以上的句号.我如何在正则表达式中检查它.

hello.me_1@email.com # <~~ valid
foo.bar#gmail.co.uk # <~~~ not valid
f.o.o.b.a.r@gmail.com # <~~~valid 
f...bar@gmail.com # <~~ not valid 
get_at_m.e@gmail  #<~~ valid
Run Code Online (Sandbox Code Playgroud)

有人可以帮我改写我的正则表达式吗?

ruby regex email validation

46
推荐指数
8
解决办法
5万
查看次数

在捆绑安装上安装Nokogiri但已经安装时出错

我在捆绑我的Gemfile时遇到问题.我已经安装了Nokogiri但是当我运行bundle install它时无法加载Nokogiri.

安装Nokogiri:

gem install nokogiri
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.6.6.2
Parsing documentation for nokogiri-1.6.6.2
Done installing documentation for nokogiri after 2 seconds
1 gem installed
Run Code Online (Sandbox Code Playgroud)

捆绑安装:

bundle install   sic@ANTHONYs-iMac
Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.2
Using minitest 5.5.1
Using thread_safe 0.3.4
Using tzinfo 1.2.2
Using activesupport 4.2.0
Using builder 3.2.2
Using …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails nokogiri bundler

33
推荐指数
4
解决办法
3万
查看次数

Ruby - Regex多行

我正在寻找搜索一些文件,看看他们是否在文件顶部有评论.

这是我正在寻找的:

#++
#    app_name/dir/dir/filename
#    $Id$
#--
Run Code Online (Sandbox Code Playgroud)

我把它作为一个REGEX并且做得很短:

:doc => { :test => '^#--\s+[filename]\s+\$Id'
if @file_text =~ Regexp.new(@rules[rule][:test])
....
Run Code Online (Sandbox Code Playgroud)

有什么建议?

ruby regex expression

0
推荐指数
1
解决办法
641
查看次数

Ruby 比较 2 个哈希值

如果键的顺序不同,有没有办法比较 2 个哈希?例如

hash1 = { "it"=> 10,"was"=>11,"the"=>14,"best"=>1,"of"=>12,"times"=>2,
          "worst"=>1,"age"=>2,"wisdom"=>1,"foolishness"=>1,"epoch"=>2,
          "belief"=>1,"incredulity"=>1,"season"=>2,"light"=>1,"darkness"=>1,
          "spring"=>1,"hope"=>1,"winter"=>1,"despair"=>1,"we"=>4,"had"=>2,
          "everything"=>1,"before"=>2,"us"=>2,"nothing"=>1,"were"=>2,"all"=>2,
          "going"=>2,"direct"=>2,"to"=>1,"heaven"=>1,"other"=>1,
          "way"=>1,"in"=>2,"short"=>1,"period"=>2,"so"=>1,"far"=>1,"like"=>1,
          "present"=>1,"that"=>1,"some"=>1,"its"=>2,"noisiest"=>1,
          "authorities"=>1,"insisted"=>1,"on"=>1,"being"=>1,
          "received"=>1,"for"=>2,"good"=>1,"or"=>1,"evil"=>1,"superlative"=>1,
          "degree"=>1,"comparison"=>1,"only"=>1 }


hash2 = {"superlative"=>1, "it"=>10, "going"=>2, "spring"=>1, "age"=>2, 
         "despair"=>1, "received"=>1, "good"=>1, "some"=>1, "worst"=>1, "was"=>11,
         "only"=>1,"us"=>2, "evil"=>1, "belief"=>1, "for"=>2, "darkness"=>1,
         "comparison"=>1, "short"=>1, "in"=>2, "present"=>1, "direct"=>2, "were"=>2,
         "way"=>1, "degree"=>1, "or"=>1, "of"=>12, "epoch"=>2, "incredulity"=>1,
         "period"=>2, "heaven"=>1, "other"=>1, "being"=>1, "its"=>2, "so"=>1,
         "authorities"=>1, "times"=>2, "we"=>4, "noisiest"=>1, "light"=>1, "hope"=>1,
         "foolishness"=>1, "everything"=>1, "far"=>1, "wisdom"=>1, "season"=>2, "like"=>1,
         "before"=>2, "had"=>2, "the"=>14, "nothing"=>1, "winter"=>1, "best"=>1,
         "that"=>1, "all"=>2, "insisted"=>1, "to"=>1, "on"=>1}
Run Code Online (Sandbox Code Playgroud)

每个散列具有相同的键。我将如何比较它们并确保每个键值都是正确的。我见过的所有问题和答案都以相同的顺序显示密钥的哈希值。有关系吗?

我试过使用: …

ruby hash ruby-on-rails

0
推荐指数
1
解决办法
2653
查看次数

标签 统计

ruby ×4

regex ×2

ruby-on-rails ×2

bundler ×1

email ×1

expression ×1

hash ×1

nokogiri ×1

validation ×1