Reputation: 56859
I am attempting to replace XML documentation comments in a large project that have been incorrectly using <item></item>
instead of <item><description></description></item>
. I figured that using the Visual Studio find and replace functionality would probably be the quickest way to do this. So, I came up with the following regex:
(?ixs)(?<=///.*<item\b[^>]*>)(?<description>[^\<]*?)(?=</\s*?item>)
In the "Find In Files" mode in Visual Studio 2015's Find and Replace functionality, the regex matches 249 lines in the project.
However, if I try to use "Find and Replace", and use <description>${description}</description>
in the "Replace with" textbox, I get zero matches.
I tried using $1
, $2
, and $+
instead of ${description}
, but in each case I get zero matches.
I also used a literal value REPLACEMENT
in the "Replace with" textbox and it replaces all 249 lines with the word REPLACEMENT
.
I tried this both in Visual Studio 2015 and 2017 with the same result.
According to MSDN, this should be the syntax for substituting the text. So why is it not working in Visual Studio?
NOTE: The project I am trying this with is https://github.com/apache/lucenenet, in case anyone wants to test under the same conditions I am.
Environment:
/// For more examples, see the <see cref="Lucene.Net.Analysis"/> namespace documentation.
/// <para/>
/// For some concrete implementations bundled with Lucene, look in the analysis modules:
/// <list type="bullet">
/// <item>Common:
/// Analyzers for indexing content in different languages and domains.</item>
/// <item>ICU:
/// Exposes functionality from ICU to Apache Lucene.</item>
/// <item>Kuromoji:
/// Morphological analyzer for Japanese text.</item>
/// <item>Morfologik:
/// Dictionary-driven lemmatization for the Polish language.</item>
/// <item>Phonetic:
/// Analysis for indexing phonetic signatures (for sounds-alike search).</item>
/// <item>Smart Chinese:
/// Analyzer for Simplified Chinese, which indexes words.</item>
/// <item>Stempel:
/// Algorithmic Stemmer for the Polish Language.</item>
/// <item>UIMA:
/// Analysis integration with Apache UIMA.</item>
Upvotes: 1
Views: 743
Reputation: 686
I have also encountered this issue (Find All and Replace All not working but Replace working in a given file) with the regular Find & Replace in Visual Studio 2015. I was performing a find in "Selection": I selected the text I wanted to run the REGEX replace over, pressed Ctrl + H for the Find & Replace tool and started typing in the REGEX (at this point Visual Studio started highlighting text within the selection). When I then clicked "Replace All" or "Find All" no results were found but I found out that if I selected the text again with the Find & Replace tool still open then Find All and Replace All started working again!
This seems like a bug as the text was already selected and became deselected as I was writing my REGEX (even though it no longer had the usual selection background colour, it did still appear to have a background highlight colour when compared to the rest of the file to indicate that it was still selected even though Find & Replace acted as though it wasn't selected!).
I don't know whether this answers your question directly as I'm not sure what mode you were using for "Find In", but if it was "Selection" then this could be the issue.
Upvotes: 0
Reputation: 16761
I can confirm the problem in VS2012. Had to change regex to account for newlines (([^\<]|\r\n)*?
instead of just [^\<]*?
). It works when replacing items one by one, but does nothing when you want to replace all. Could be a bug.
This works though (not using lookaheads and lookbehinds):
Find: <item>(([^\<]|\r\n)*)
Replace with: <item><description>$1</description>
Upvotes: 2