2 Replies Latest reply: Apr 30, 2012 7:10 AM by Tony T1
Tony T1 Level 6 Level 6 (8,830 points)

I can't seem to get ungreedy (?) to work in grep.

 

echo "This is a <EM>first</EM> test" | grep -E -o '<.+?>'

returns <EM>first</EM> (not <EM> </EM>)

 

(I can use '<[^>]+>', but why isn't '<.+?>' working?)

 

Tony


MacBook Air, MacBook, Mac mini, Mac OS X (10.7.3)
  • BobHarris Level 6 Level 6 (15,695 points)

    I do not see in "man grep" (nor "man re_format") where it talks about supporting .+? syntax.  Are you confusing a different platform's grep or perhaps perl's regular expressions?

  • Tony T1 Level 6 Level 6 (8,830 points)

    I didn't see it in the man page either, but I thought GNU grep supported ungreedy, but wasn't sure.

     

    ....just tried -P, so ungreedy does work in grep with -P, --perl-regexp