0

in osx (mac) command line i try to use grep command :

grep '(?<!class) cselectnone' -s *

it should match 'def cselectnone()' but NOT 'class cselectnode()'. But in fact i can't match 'def cselectnone()'.

I try this code using http://regexr.com/v1/ and https://regex101.com/ And i got the correct result. But the result in osx command line was not correct . Why is it?

andio
  • 1,574
  • 9
  • 26
  • 45
  • Have you tried `grep -P ...`? – Anton Savin Apr 06 '16 at 19:26
  • 1
    And assuming `grep -P` isn't an option, just `grep 'cselectnone' | grep -v 'class'`? – Mr. Llama Apr 06 '16 at 19:28
  • @AntonSavin -P didn't work. – andio Apr 06 '16 at 19:33
  • @Mr.Llama : yes i can use that grep -v. I'm just curious with that code. it should fine ( tested on regex101) , i need the reason why it breaks? – andio Apr 06 '16 at 19:35
  • 2
    @andio - Simply put, the default GNU grep [doesn't support negative lookbehinds](http://stackoverflow.com/a/2490018/477563). If your version of grep supports the `-P` option for PCRE, that should work. If not, you may need to consider tackling this differently. – Mr. Llama Apr 06 '16 at 19:41
  • @Mr.Llama : i see ... i thought GNU grep has full compatibility. Thanks. – andio Apr 07 '16 at 02:20

0 Answers0