How to modify part of content with regular in Visual Studio 2017



Before you start, if you have any questions about the installation, you can refer to this article: / / OK, let’s start the body of this article:

To implement a gadget in the project recently, you need to add the corresponding [description] feature according to the content of the class’s attribute < summary >. The effect to be implemented is as follows

Before amendment:

/// <summary>
///Bar code
/// </summary>
 public List<GoodsBarcodeEditModel> Barcodes { get; set; }

After amendment:

/// <summary>
///Bar code
/// </summary>
[description ("barcode")]
public List<GoodsBarcodeEditModel> Barcodes { get; set; }

As a non Virgo program ape, but with Virgo characteristics, keep in mind dry (don’t repeat yourself), don’t want to waste time on copy paste, so think about whether the regular in vs’s find and replace will have the function of supporting partial replacement. Following this idea, find the Microsoft document “replacement in regular expression”, which contains $value replacement capture group To meet my needs.

The next step is simple


Code segment Regular grouping packet number
/// <summary> (///\s<.*\n*) $1
Blank space (\s*) $2
/// (///) $3
Blank space (\s*) $4
bar code (\w*) $5
Line feed (\n*) $6
/// </summary> (\s*///.*) $7

So we use the following combination to get the result we want

$1$2$3$4$5$6$7 [Description(“$5”)]

The final effect is as follows:


The above is the whole content of this article. I hope that the content of this article has a certain reference learning value for everyone’s study or work. If you have any questions, you can leave a message and exchange. Thank you for your support for developepaar.