I am trying to run grep with the following regex:
(?<!key:)(?<!orKey:)(?<!isEqualToString:)\@\"[A-Za-z0-9]*\"
First try:
$ grep -r -n -H -E (?<!key:)(?<!orKey:)(?<!isEqualToString:)\@\"[A-Za-z0-9]*\" ./ -bash: !key: event not found
Ok, so I need to avoid the "!" s ...
$ grep -r -n -H -E (?<\!key:)(?<\!orKey:)(?<\!isEqualToString:)\@\"[A-Za-z0-9]*\" ./ -bash: syntax error near unexpected token `('
Ok, so I need to get away from "(" s ...
$ grep -r -n -H -E \(?<\!key:\)\(?<\!orKey:\)\(?<\!isEqualToString:\)\@\"[A-Za-z0-9]*\" ./ -bash: !key:)(?: No such file or directory
So, do I need to quote a line?
$ grep -r -n -H -E '\(?<\!key:\)\(?<\!orKey:\)\(?<\!isEqualToString:\)\@\"[A-Za-z0-9]*\"' ./
It returns no results ... but I tried a simpler regular expression that has no statements with a negative expression, and it works fine ... I also used TextWrangler with this regular expression, and it really works, so I can only assume that I am doing something wrong on the command line here.
EDIT:
If I use the -p option:
$ grep -r -n -H -E -P '\(?<\!key:\)\(?<\!orKey:\)\(?<\!isEqualToString:\)\@\"[A-Za-z0-9]*\"' ./ grep: conflicting matchers specified
An example of the contents of a file that must match:
NSString * foo = @"bar";
An example of the contents of a file that should NOT match:
return [someDictonary objectForKey:@"foo"];
source share