0

Say I have 3 files and I want to exclude 2 of them from find.

/tmp/test/c
/tmp/test/a
/tmp/test/b
# works
find /tmp/test -type f -not -regex "/tmp/test/\(a\|b\)"

# does not work
find /tmp/test -type f -not -regex "/tmp/test/(a|b)"

Single or double quote do not seem to matter here.

Why is this the case? I would think no escaping is needed, as shell does not touch the regex as the regex is in quotes.

bill
  • 650
  • 8
  • 17
  • In all "languages", characters with two potential meanings (here: literal parenthesis or group delimiter) must be escaped for one of the meanings. Which one is chosen by escaping differs from one language to the other. – Peter - Reinstate Monica Jun 13 '23 at 12:24
  • How would you include a literal parenthesis in your pattern? – Christian.K Jun 13 '23 at 12:24
  • 1
    ` -regextype egrep -regex "/tmp/test/(a|b)"` It has nothing to do with the shell, it is a regex thing. – Jetchisel Jun 13 '23 at 12:26
  • 2
    Your `find` (I‘m guessing it‘s the GNU one) uses BRE syntax, unless you change it with `-regextype`. – Biffen Jun 13 '23 at 12:26

0 Answers0