linux shell grep 非贪婪匹配

默认情况下匹配都是贪婪模式,如果要改成非贪婪模式,只需要量词后面加上一个问号?

贪婪模式常用的量词有:

  • {m,n}
  • {m,}
  • ?
  • *
  • +

如果改成非贪婪模式,只需这样:

  • {m,n}?
  • {m,}?
  • ??
  • *?
  • +?

Linux上grep执行不生效,和bsd和GUN协议有关,bsd用grep -oE    GUN用grep -oP

l例子:  centos上执行  echo he-llo-llo|grep -oP 'he.*?llo'

参考链接:http://www.it1352.com/835546.html

https://www.jianshu.com/p/974dee8953e6

发布了15 篇原创文章 · 获赞 5 · 访问量 9057

猜你喜欢

转载自blog.csdn.net/qq_35702095/article/details/103720235