Easy RegEx Find and Replace in Notepad++

Previously, we’ve blogged about customizing the Toolbar within Notepad++ and, in my case, the benefit in doing so was to add some key functions to the Toolbar from the “XML Tools” plug-in I often use. In working with a lot of XML, XSLT and even HTML within Notepad++, I often have a need to find, or even find/replace, specific tags or script blocks. Notepad++ makes this easy with support for RegEx via the “regular expression” Search Mode.

RegExFind

Given the following XML snippet, let’s look at some use cases for RegEx finds:

<SetList Scope=”Request”>Tasks</SetList>
<SetVar Name=”Cmd”>ExportList</SetVar>
<SetVar Name=”XMLDATA”>TRUE</SetVar>
<SetVar Name=”ExtendedFieldsProperties”>0</SetVar>
<SetVar Name=”ExcludeViews”>TRUE</SetVar>
<SetVar Name=”ExcludeFields”>TRUE</SetVar>

In Notepad++, we could easily find our <SetList> element using this RegEx:

<SetList.*>.*</SetList>

Then if we wanted all the <SetVar> elements, regardless of their Name attribute or value, we could use this RegEx:

<SetVar.*>.*</SetVar>

If we wanted to be more explicit and say only find the <SetVar> element whose Name attribute began with an “E”, we could use:

<SetVar Name=”E.*>.*</SetVar>

Or perhaps we want to find all the <SetVar> elements where the text value is “TRUE”:

<SetVar.*>TRUE</SetVar>

As you can see, these simple tricks could save you time & effort if wanting to find specific tags – or clean up using Find/Replace with a blank replace – using the regular expression Search Mode in Notepad++.

Comments are closed.