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 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析