title: CMake regex match directories in list
body: <p>So I have list of files (or values) like this</p>
  
  <pre><code>set(HEADER_FILES DirA/header1.h DirA/header2.hpp
                  DirB/header3.h DirB/stuff.hpp)
  </code></pre>
  
  <p>Then how do I get sub list of files only in DirA ? I'm using CMake 2.8.x and I tired regex match:</p>
  
  <pre><code>string(REGEX MATCHALL "DirA/(.+)" DirA_FILES ${HEADER_FILES})
  </code></pre>
  
  <p>But result is just copy of the orginal string like: "DirA/header1.h DirA/header2.hpp DirB/header3.h DirB/stuff.hpp" or nothing.</p>
  
  <p>Well again as always, while writing this question I solved it:</p>
  
  <pre><code>set(SubListMatch)
  foreach(ITR ${HEADER_FILES})
      if(ITR MATCHES "(.*)DirA/(.*)")
          list(APPEND SubListMatch ${ITR})
      endif()
  endforeach()
  </code></pre>
  
  <p>But CMake is quite new thing to me so how do I wrap that code into function? I have never written any CMake functions so far.</p>