Menu

#4 RegEx for XML comment too greedy

open
nobody
None
5
2007-09-13
2007-09-13
Edward Brey
No

The default Break Flow String for "XML comment on a line by itself" is too greedy in the sense that it spans multiple XML tags. The result is that a commend like the following (example taken from .NET Framework) doesn't get reflowed:

class String
{
... [Other comments.] ...
/// <returns>true if the <paramref name="value"/> parameter occurs within this string, or if <paramref name="value"/> is the empty string (""); otherwise, false.</returns>
public bool Contains(string value)
{
...
}
...
}

This is the Regex: ^\s*<.+?>\s*$
The problem is that it eats all characters up until the close of the last XML tag.

Fortunately, the fix and workaround is simple. Use this RegEx instead: ^\s*<[^>]+>\s*$

Discussion


Log in to post a comment.

MongoDB Logo MongoDB