Reputation: 13
In My Project, I want to add CssClass to All asp:Buttons which don't have the CssClass attribute.How can I use regular expressions to search and replace All?
search and replace this
<asp:Button ID="buttonSearch" runat="server" Text="Search" OnClick="buttonSearch_Click" />
into the following
<asp:Button ID="buttonSearch" runat="server" Text="Search" OnClick="buttonSearch_Click" CssClass="button-default" />
Upvotes: 0
Views: 899
Reputation: 328
It seems that Visual Studio now supports Find and Replace with Regular Expressions: https://learn.microsoft.com/en-us/visualstudio/ide/using-regular-expressions-in-visual-studio?view=vs-2019#capture-groups-and-replacement-patterns
Microsoft says
Visual Studio uses .NET regular expressions to find and replace text.
Before using Regular Expressions in the Find and Replace interface, you just have to make sure to press the "Regular Expressions" button (the buttons contains a symbol like this: .*):
Note: as shown in the picture, you can also press Alt + E to enable regular expressions in the Find and Replace interface!
You can find more informations about the regular expressions & the Find and Replace feature here
Upvotes: 0
Reputation: 336088
You can't do it with "regular" VS find/replace regexes because they don't support lookaround assertions.
You can do it using a special plugin, though. It's called Regular Expressions Margin and supports .NET style regexes:
Search for
<asp:Button\b(?![^<>]*\bCssClass)([^<>]*)/>
and replace all with
<asp:Button\1 CssClass="button-default" />
Upvotes: 0
Reputation: 13
ok, I resolve it by myself.
ctrl+shift+H
find what
{\<asp\:Button(:b+<:w>=:q(\n)*)*}{(:b)*/*\>}
replace with
\1 CssClass="button-default" \2
Upvotes: 1
Reputation: 8333
search for <asp:Button
and replace it with <asp:Button CssClass="button-default"
in whole of your project.
Upvotes: 0