In this command, I want to extract strings that are like *.com or *.net, where * is not a dot. I wrote this:

grep -P -E '^[^.]+\.com$ |^[^.]+\.net$' example.csv 

I get this error:

grep: conflicting matchers specified

Can you clarify?

  • 4
    This error just means that -E (for extended regular expression) and -P (Perl-compatible regular expression (PCRE)) options are exclusive and cannot be used both at same time. Choose only one. This is not a regexp error. – el-teedee Apr 21 at 21:39

You can't use both PCRE (-P) and Extended Regular Expressions (-E) at the same time. In this case, it seems as if you don't use PCRE expressions at all, so you could just drop the -P. You also can't expect to match a space after $.

Combining most of the expression into a shorter one:

grep -E '^[^.]+\.(com|net)$'


grep -E -x '[^.]+\.(com|net)'

The -x option will cause grep to only match complete lines.

The expression matches a non-zero number of non-dot characters, followed by a dot and then either net or com.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.