first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

Visual Studio.NET: Searching and Replacing with Regular Expressions

Searching for text with Regular Expressions should be straight forward. I constantly read this reference at design-time:

ms-help://MS.VSCC/MS.MSDNVS/vsintro7/html/vxgrfregularexpressionss.htm

What was elusive to me was how to replace what I found using the Replace All command. This is done by "tagging" expressions with brackets {}. So the following regular expression will look for HTML numerical attributes without XHTML-friendly quotes:

\\=[0-9]+

But this expression will not let me insert quotes after the equal sign. This expression will:

{\\=}{[0-9]+}

This expression works just like the previous one. All we have now are two tagged sub-expressions that can be located with the \\n syntax. The corresponding replace expression is therefore:

\\1"\\2"

This says, "Insert a quote after the first set of tagged text characters and another quote after the second set of tagged text characters."

mod date: 2003-01-17T22:42:11.000Z