How to do a non-greedy match in grep?

后端 未结 7 2089
深忆病人
深忆病人 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:41

    grep

    For non-greedy match in grep you could use a negated character class. In other words, try to avoid wildcards.

    For example, to fetch all links to jpeg files from the page content, you'd use:

    grep -o '"[^" ]\+.jpg"'
    

    To deal with multiple line, pipe the input through xargs first. For performance, use ripgrep.

提交回复
热议问题