douwen3362 2011-04-17 20:29
浏览 67
已采纳

使用名称解析电子邮件地址(FROM或TO) - 不一定符合rfc 2822

I have an email field that may be formatted in a few different ways.

  1. hello@world.com

  2. "hello world" <hello@world.com>

  3. hello world <hello@world.com>

I would like to capture both the hello world string (if it's there) and the email address (if it's there). I have a regular expression that almost works, but it doesn't quite.

sed -r  's/"?([^"]+)*"?\s<?([^>]+@[^>]+)>?/["\1","\2"]/' <<< 'Hello World <helloworld@gmail.com>'

Please help?

  • 写回答

3条回答 默认 最新

  • douzhang1852 2011-04-17 20:52
    关注

    Update:

    This should do what you want:

    ^(?:"?([^@"]+)"?\s)?<?([^>]+@[^>]+)>?$
    

    This will store the first part, if there is one, into the first capturing group and the email address int o the second group.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作