title: Exclude files and directories from find . function that match some regular expression
body: <p>I am using Bash to go through some directories and files. I am using find function as shown in the example and I need to exclude all directories (and all it includes) and files which name match some regular expression (which can be anything).</p>
  
  <pre><code>while read file
  do 
      do_stuff "${file}" 
  done &lt;&lt;&lt; "$(find ${SOME_DIR}")
  </code></pre>
  
  <p>I already tried using -not -name args but that only excluded that one specific directory, and processed all in that directory.</p>
  
  <p>Btw. I found some similar questions in here, but all are quite specific. This regular expression can be really anything.</p>
  
  <p>example: REGEX='^bbb$'</p>
  
  <p>dir structure:
  ./test</p>
  
  <p>├── bbb</p>
  
  <p>│   └── some file</p>
  
  <p>├── -e</p>
  
  <p>├── dir2</p>
  
  <p>│   └── bbb</p>
  
  <p>├── a</p>
  
  <p>├── b</p>
  
  <p>└── c</p>
  
  <p>So here I would like find to exclude bbb directory and all thats in it and bbb file.</p>
  
  <p>Another regex example:
  '^.<em>b.</em>$' -- all files and directories that has b in their name</p>