Thanks, Fraser. Of course...<br><br>If you need to escape a backslash such that the regular expression itself contains a backslash at a certain point, then you need to double it up. For example to match the backslash character itself, you need to use &quot;[\\]&quot;, but to encode other escape chars directly that CMake knows about, you only need one. (Just as you only need one to put the real &quot;\n&quot; character into the string in the first place.<br>
<br>This code shows that &quot;Matches2&quot; contains your expected results:<br><br><br>cmake_minimum_required(VERSION 2.8)<br><br>set(contents &quot;Hello\nWorld!&quot;)<br>message(&quot;contents=&#39;${contents}&#39;&quot;)<br>
<br>string(REGEX MATCHALL &quot;Hello[\\r\\n\\t ]*World!&quot; matches ${contents})<br>message(&quot;Matches1:&quot;)<br>foreach(match ${matches})<br>  message(&quot;match=&#39;${match}&#39;&quot;)<br>endforeach()<br><br>
string(REGEX MATCHALL &quot;Hello[\r\n\t ]*World!&quot; matches ${contents})<br>message(&quot;Matches2:&quot;)<br>foreach(match ${matches})<br>  message(&quot;match=&#39;${match}&#39;&quot;)<br>endforeach()<br><br><br><br>
<div class="gmail_quote">On Mon, Jan 10, 2011 at 5:38 PM, Fraser Hutchison <span dir="ltr">&lt;<a href="mailto:fraser.hutchison@googlemail.com">fraser.hutchison@googlemail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">


  
    
    
  
  <div bgcolor="#ffffff" text="#000000">
    I think if you remove the double &quot;\\&quot; it should work, i.e. use:<br>
    <br>
    <code>string (REGEX MATCHALL
      &quot;TEST_?F?\\([A-Za-z_0-9]+,[\r\n\t\\\\]*[A-Za-z_0-9 ]+\\)&quot;
      found_tests ${contents})</code><br>
    <br>
    Cheers,<br><font color="#888888">
    <br>
    Fraser.</font><div><div></div><div class="h5"><br>
    <br>
    <br>
    <br>
    <br>
    On 1/10/2011 5:04 PM, Ben Medina wrote:
    <blockquote type="cite">
      <pre>It doesn&#39;t seem to work:

cmake_minimum_required (VERSION 2.8)

set (contents &quot;Hello\nWorld!&quot;)
message (&quot;${contents}&quot;)
string (REGEX MATCHALL &quot;Hello[\\r\\n\\t ]*World!&quot; matches ${contents})

message (&quot;Matches:&quot;)
foreach (match ${matches})
    message (&quot;${match}&quot;)
endforeach ()

This produces no matches. If you replace &quot;\n&quot; with &quot; &quot; in the contents
string, then you get a match.

Thanks,
Ben

On Fri, Jan 7, 2011 at 12:18 PM, David Cole <a href="mailto:david.cole@kitware.com" target="_blank">&lt;david.cole@kitware.com&gt;</a> wrote:
</pre>
      <blockquote type="cite">
        <pre>It should work.

But I&#39;m pretty sure we don&#39;t recognize &quot;\s&quot; for white space. Try &quot;[
\\t\\n\\r]&quot; instead of \\s.

But..... watch out for white space after &quot;(&quot; and before &quot;)&quot; too. You might
miss some lines if they have spaces there.


On Fri, Jan 7, 2011 at 2:55 PM, Ben Medina <a href="mailto:ben.medina@gmail.com" target="_blank">&lt;ben.medina@gmail.com&gt;</a> wrote:
</pre>
        <blockquote type="cite">
          <pre>I need to parse a C++ file for Google Test macros. (I&#39;m aware the
GTEST_ADD_TESTS provided by FindGtest.cmake, but I need the test list
for my own purposes). I had been using a regex similar to the one in
GTEST_ADD_TESTS to match tests:

string (REGEX MATCHALL &quot;TEST_?F?\\([A-Za-z_0-9 ,]+)\\)&quot; found_tests
${contents})

But this doesn&#39;t work when the test is split onto two lines, like this:

TEST(SampleTest,\
    MultilineTest)

So, I&#39;ve been trying to build a regex that will match tests split onto
multiple lines. This should work:

string (REGEX MATCHALL &quot;TEST_?F?\\([A-Za-z_0-9
]+,[\\s\\\\]*[A-Za-z_0-9 ]+\\)&quot; found_tests ${contents})

After the comma, the regex should greedily match all whitespace
(including newlines) via the &quot;\\s&quot; and backslashes via the &quot;\\\\&quot;
(Note that all special characters are escaped). This works in other
regex engines, but fails in CMake.

Is this possible in CMake, or do I need to use another tool?

Here is my test file (named tests.cpp):

TEST(SampleTest, SingleLineTest)
TEST(SampleTest,\
    MultilineTest)
TEST_F(SampleTest, SingleLineFixtureTest)
TEST_F(SampleTest,\
    MultilineFixtureTest)

And my CMakeLists.txt:

cmake_minimum_required (VERSION 2.8)

file (READ &quot;tests.cpp&quot; contents)
string (REGEX MATCHALL &quot;TEST_?F?\\([A-Za-z_0-9
]+,[\\s\\\\]*[A-Za-z_0-9 ]+\\)&quot; found_tests ${contents})
message (&quot;Found tests:&quot;)
foreach (test ${found_tests})
   message (&quot;${test}&quot;)
endforeach ()

Thanks,
Ben
_______________________________________________
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a>

Visit other Kitware open-source projects at
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a>

Please keep messages on-topic and check the CMake FAQ at:
<a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a>

Follow this link to subscribe/unsubscribe:
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a>
</pre>
        </blockquote>
        <pre></pre>
      </blockquote>
      <pre>_______________________________________________
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a>

Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a>

Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a>

Follow this link to subscribe/unsubscribe:
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a>
</pre>
    </blockquote>
  </div></div></div>

</blockquote></div><br>