Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>(?&lt;=#if DEBUG(?:(?!#endif\b).)*)Logging\.Log[^\r\n]*(?=.*#endif) </code></pre> <p>will match <code>Logging.Log</code> and whatever else follows on that line only if it's between <code>#if DEBUG</code> and <code>#endif</code>. Note that you need to use <code>RegexOptions.Singleline</code> for this to work. This regex relies on a feature that only few regex engines have, namely infinite repetition inside <a href="http://www.regular-expressions.info/lookaround.html" rel="nofollow">lookbehind assertions</a>. Fortunately, .NET is among those.</p> <p>In C#:</p> <pre><code>StringCollection resultList = new StringCollection(); Regex regexObj = new Regex(@"(?&lt;=#if DEBUG(?:(?!#endif\b).)*)Logging\.Log[^\r\n]*(?=.*#endif)", RegexOptions.Singleline); Match matchResult = regexObj.Match(subjectString); while (matchResult.Success) { resultList.Add(matchResult.Value); matchResult = matchResult.NextMatch(); } </code></pre> <p><strong>Explanation:</strong></p> <pre><code># from the current position, look behind in the string to check... (?&lt;= # whether it is possible to match... #if DEBUG # the literal text # if DEBUG (?: # followed by... (?!#endif\b) # (as long as we can't match #endif along the way) . # any character )* # any number of times ) # end of lookbehind assertion. Logging\.Log # Then match Logging.Log, [^\r\n]* # followed by any character(s) except newlines. (?= # as long as there is (further up ahead)... .*#endif # any number of characters, followed by #endif ) # end of lookahead </code></pre> <p>If you're sure that every <code>#if DEBUG</code> ends with an <code>#endif</code>, then you can drop the <code>(?=.*#endif)</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload