Pregunta

I have some source with backslash-style Doxygen comments (eg. \brief Text), and am trying to use Visual Studio 2013 RegExs to help convert to XML Docs (eg. <summary>Text</summary>).

But I've run into problems where it captures an end of line I want to avoid:

Here's my Current Find/Replace, and the result:

Find: \\brief.\s(?<brief>.*)[\r?\n]{1}

Intention: Look for \brief, whitespace, a set of characters (captured as "brief"), exactly 1 newline.

Replace: <summary>${brief}</summary>

Intention: Replace with XML tags, the captured "brief" text, specifically NOT including the newline.

Actual result:

/// \brief  My Brief Text for this function
///

/// <summary> My Brief Text for this function
</summary>///

It appears that the newline was captured as part of the Tagged text, even though I tried to avoid that.
I'm trying to get the </summary> closing tag on the same line as the rest of the text.

What am I doing wrong here?

¿Fue útil?

Solución

To avoid newline characters as part of the capture, you can search for:

\\brief\s*([^\n\r])+

You can replace with <summary>$1</summary>

The [^\n\r] is a negated character class that matches any character that is neither a newline nor a carriage return. By adding the + quantifier, we manage to match the whole line.

What were the problems with the original?

  1. the .\s is the first problem. The dot matches the space character, then there is no space left to match for the \s
  2. the ? in the [\r?\n] serves no purpose. It does not make the \r optional, but says that a literal question mark is one of the allowable chars to be matched at that position.
  3. the {1} is redundant, as a [charclass] only matches one character unless it is followed by a quantifier.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top