Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a .Net flavored Regex for partly parsing .Net flavor patterns, which should get pretty close:</p> <pre><code>\A (?&gt; \\. # Capture an escaped character | # OR \[\^? # a character class (?:\\.|[^\]])* # which may also contain escaped characters \] | # OR \(\?(?# inline comment!)\# (?&lt;Comment&gt;[^)]*) \) | # OR \#(?&lt;Comment&gt;.*$) # a common comment! | # OR [^\[\\#] # capture any regular character - not # or [ )* \z </code></pre> <p>Luckily, in .Net each capturing group remembers all of its captures, and not just the last, so we can find all captures of the <code>Comment</code> group in a single parse. The regex pretty much parses regular expression - but hardly fully, it just parses enough to find comments.<br> Here's how you use the result:</p> <pre><code>Match parsed = Regex.Match(pattern, pattern, RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline); if (parsed.Success) { foreach (Capture capture in parsed.Groups["Comment"].Captures) { Console.WriteLine(capture.Value); } } </code></pre> <p>Working example: <a href="http://ideone.com/YP3yt" rel="nofollow">http://ideone.com/YP3yt</a></p> <p>One last word of caution - this regex assumes the whole pattern is in <code>IgnorePatternWhitespace</code> mode. When it isn't set, all <code>#</code> are matched literally. Keep in mind the flag might change multiple times in a single pattern. In <code>(?-x)#(?x)#comment</code>, for example, regardless of <code>IgnorePatternWhitespace</code>, the first <code>#</code> is matched literally, <code>(?x)</code> turns the <code>IgnorePatternWhitespace</code> flag back on, and the second <code>#</code> is ignored.</p> <p>If you want a robust solution you can use a regex-language parser.<br> You can probably adapt the .Net source code and extract a parser:</p> <ul> <li><a href="http://referencesource.microsoft.com/#System/regex/system/text/regularexpressions/RegexParser.cs" rel="nofollow">Reference Source - RegexParser.cs</a></li> <li><a href="https://github.com/dotnet/corefx/blob/master/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexParser.cs" rel="nofollow">GitHub - RegexParser.cs</a></li> </ul>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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