Q:

backslashes in regular expressions

Someone asked how to find all files of certain file types, and one of the answers was:
 find /path/to -regex ".*\.\(jpg\|gif\|png\|jpeg\)" > log

I'm trying to understand the backslashes better.  The first backslash is saying to take the period as literal, not as pattern matching, is that right?   If so, why is the second backslash needed, and the third?   It seems like the second backslash is saying take the ( as a literal character.

A:

\( and \| are just default regex (emacs) syntax which requires parentheses and alternation | to be escaped. You can use an advanced regex type and avoid excessive escaping like this:
find /path/to -regextype posix-egrep -regex ".*\.(jpg|gif|png|jpeg)" > log

As per man find:

-regextype type
Changes the regular expression syntax understood by -regex and -iregex tests which occur later  on  the  command
      line. Currently-implemented  types  are  emacs  (this is the default), posix-awk, posix-basic, posix-egrep and posix-extended.

