How to do a non-greedy match in grep?

后端 未结 7 2092
深忆病人
深忆病人 2020-11-30 17:30

I want to grep the shortest match and the pattern should be something like:


...
...
...

... mean

7条回答
  •  情书的邮戳
    2020-11-30 17:48

    Actualy the .*? only works in perl. I am not sure what the equivalent grep extended regexp syntax would be. Fortunately you can use perl syntax with grep so grep -P would work but grep -E which is same as egrep would not work (it would be greedy).

    See also: http://blog.vinceliu.com/2008/02/non-greedy-regular-expression-matching.html

提交回复
热议问题