drpfu51608120170 2017-02-22 02:19
浏览 31
已采纳

正则表达式 - 将组1作为“完全匹配”/组0

Given the following examples, I want to get the email address

Eg. 1: some standard text.   Bugs Bunny bugs@gmail.com 0411111111 more standard text 
Eg. 2: some standard text.   Bugs The Bunny bugs@gmail.com 0411111111 more standard text
Eg. 3: some standard text.   Bugs-Bunny bugs.bunny@gmail.com 0411111111 more standard text
Eg. 4: some standard text.   Bugs bugs.bunny@gmail.com +6141 111 111 more standard text
Eg. 5: some standard text.   Bugs o'Bunny bugs@gmail.com 0411111111 more standard text 

This will do it: (?<=some standard text. )(?:.*?)([^\s]+@[^\s]+) https://regex101.com/r/A29hjE/9

But the email address is in group 1. I need it to be group 0 or the full match because this regex will be created dynamically by some code in which all other regex's produce their findings as the full match.

I don't know enough about groups, but I know I need the first email address after the some standard text. bit and, like I said, it need's to be the full match.

  • 写回答

3条回答 默认 最新

  • dongnigeng1295 2017-02-22 02:26
    关注

    If you change your regex to simply be ([^\s]+@[^\s]+), the full result should be just the email address.

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

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看