Regex Match Whole Multiline Comment Cointaining Special Word
<p>I've been trying to design this regex but for the life of me I could not get it to not match if */ was hit before the special word.</p>

<p>I'm trying to match a whole multi line comment only if it contains a special word.  I tried negative lookaheads/behinds but I could not figure out how to do it properly.</p>

<p>This is what I have so far:
<code>(?s)(/\*.+?special.+?\*/)</code></p>

<p>Am I close or horribly off base? I tried including <code>(?!\*/)</code> unsuccessfully.</p>

<p><a href="https://regex101.com/r/mD1nJ2/3" rel="nofollow">https://regex101.com/r/mD1nJ2/3</a></p>

<p>Edit: I had some redundant parts to the regex I removed.</p>

<p>You were not totally off base:</p>

<pre><code>/\*                 # match /*
(?:(?!\*/)[\s\S])+? # match anything lazily, do not overrun */
special             # match special
[\s\S]+?            # match anything lazily afterwards
\*/                 # match the closing */
</code></pre>

<p>The technique is called a tempered greedy token, see <a href="https://regex101.com/r/mD1nJ2/4" rel="nofollow"><strong>a demo on regex101.com</strong></a> (mind the modifiers, e.g. <code>x</code> for verbose mode !).<br>
<hr>
You might want to try another approach tough: analyze your document, grep the comments (using eg <code>BeautifulSoup</code>) and run string functions over them (<code>if "special" in comment...</code>). </p>

python regex