【问题标题】:How do I write this regex in ruby?如何在 ruby​​ 中编写这个正则表达式?
【发布时间】:2015-04-27 02:02:45
【问题描述】:

我有一个这样的字符串:

"\"john smith\" <jsmith@gmail.com>, \"joe@gmail.com\" <joe@gmail.com>"

我需要的是一个 ruby​​ 哈希,看起来像:

{ 'john smith' => 'jsmith@gmail.com', 'joe@gmail.com => 'joe@gmail.com' }

我将如何使用正则表达式来做到这一点?

【问题讨论】:

    标签: ruby regex hashmap


    【解决方案1】:
    Hash[str.scan(/"(.*?)" <(.*?)>/)]
    # => {"john smith"=>"jsmith@gmail.com", "joe@gmail.com"=>"joe@gmail.com"}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 1970-01-01
      • 2017-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多