title: python regex to match multi-line preprocessor macro
body: <p>What follows is a regular expression I have written to match multi-line pre-processor macros in C / C++ code. I'm by no means a regular expressions guru, so I'd welcome any advice on how I can make this better.</p>
  
  <p>Here's the regex:</p>
  
  <pre><code>\s*#define(.*\\\n)+[\S]+(?!\\)
  </code></pre>
  
  <p>It should match all of this:</p>
  
  <pre><code>#define foo(x) if(x) \
  doSomething(x)
  </code></pre>
  
  <p>But only some of this (shouldn't match the next line of code:</p>
  
  <pre><code>#define foo(x) if(x) \
  doSomething(x)
  normalCode();
  </code></pre>
  
  <p>And also shouldn't match single-line preprocessor macros.</p>
  
  <p>I'm pretty sure that the regex above works - but as I said, there probably a better way of doing it, and I imagine that there are ways of breaking it. Can anyone suggest any?</p>