How to fix "grep: Unmatched [, [^, [:, [., or [=" error when using regex

I am trying to located [items1, [items2 and such terms in all files. So I typed the following at shell prompt:

grep '[items' *

I am not sure by the following message on screen:

grep: Unmatched [, [^, [:, [., or [=

How to fix it?

When you need to match [ escape it by adding \. For instance:

grep '\[items' *
1 Like

When using grep regular expression, [ act as a special character. Do you need [? Then add a backslash to escape it. Check BRE page Regular Expressions

1 Like

you need -F flag here if you are lazy to fix escapes - it will take the pattern as fixed string instead of regexp

What does -F do here?

It will disable regular expressions. So [ and other regexp treated as text.