Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » PC / PC Tips » A Simple Guide And Most Common RegEx Usage With Notepad++

A Simple Guide And Most Common RegEx Usage With Notepad++

Searching a string using the ‘Find‘ or ‘Find & Replace‘ function in text editors highlights the relevant match (e.g. searching ‘le‘ highlights it inside words such as ‘apple‘, ‘please’ etc). However, some advanced editors such as Notepad++ (I mention Notepad++ in my examples since it’s my favorite so far!) supports the use of regex, which recently saved me hours of manually replacing strings and numeric values in files containing HTML and javascript codes.

The Best Feature In Extended Search Mode:

One of the major disadvantages of using regular expressions in Notepad++ was that it did not handle the newline character well—especially in Replace. Now, we can use an Extended search mode to make up for this shortcoming. Together, Extended and Regular Expression search modes give you the power to search, replace, and reorder your text in ways that were not previously possible in Notepad++.

Search Modes In The Find/Replace Dialogue Box:

The Find tab (accessible using Search > Find or the keyboard shortcut Ctrl+F) gives access to searching and counting. The Replace tab (Search > Replace or Ctrl+H) is similar but allows you to also replace the matched text after it’s found. The Find in Files tab (Search > Find in Files or Ctrl+Shift+F) allows you to search and replace in multiple files with one action. The Mark tab (Search > Mark…) allows you to apply red-marking (a red background to matched text; see (Preferences > Style Configurator > Global Styles > Find Mark style](../preferences/#global-styles)) to certain sections of text, and to add “bookmarks” to the lines that matched text is found upon.

Note: Search option choices made by the user are remembered across invocations of Notepad++.

List Of Find / Replace Dialogue Box Features:

All the dialog-based have certain features in common, though some are disabled under certain circumstances.

  • Find what edit box with dropdown history: this is the text you are searching for
  • Replace with edit box with dropdown history: this is the text that will replace what was matched
  • In selection: If you have a region of text selected, and In the selection is enabled, it will only Count, Replace All, or Mark All within that selection of text, rather than in the whole document (other buttons, such as Find Next, will continue to work on the whole document)
  • Backward direction: normally, searches go forward (down the page); with this option, they will go backward (up the page)
  • Match whole word only: if enabled, searches will only match if the result is a whole word (so “it” will not be found inside “hitch”)
  • Match case: if enabled, searches must match in case (so a search for “it” will not find “It” or “IT”). The regular expression i flag will override this checkbox, where (?i) will make the search case insensitive, and (?-i) will make the search case sensitive.
  • Wrap Around: if enabled, when the search reaches the end of the document, it will wrap around to the beginning and continue searching
  • Search Mode: this determines how the text in the Find what and Replace with will be treated
    • Normal: all text is treated literally.
    • Extended (\n, \r, \t, \0, \x…): use certain “wildcards”, as described in Extended Search Mode (below)
    • Regular Expression: uses the Boost regular expression engine to perform very powerful search and replace actions, as explained in Regular Expressions (below)
      • .matches newline: in regular expressions, with this disabled, the regular expression. matches any character except the line-ending characters (carriage-return and/or linefeed); with this enabled, also matches the line-ending characters. As an alternative to using this checkbox, begin the Find what box text with (?-s) to obtain the unchecked behavior of .matches newline, or with (?s) to get its checked behavior.
  • Transparency: these settings affect the dialog box. Normally, the dialog box is opaque (can’t see the text beneath), but with these settings, it can be made semi-transparent (can partially see the text beneath)
    • On losing focus: if this is chosen, the dialog will be opaque when you are actively in the dialog box, but if you click in the Notepad++ window, the dialog will become semi-transparent
    • Always: if this is chosen, the dialog will be semi-transparent, even when you are actively in the dialog box
    • Slider Bar: sliding it right makes the dialog more opaque; sliding it left makes it more transparent.
      • Be careful when sliding it to the extreme left: you might not be able to see the dialog box anymore
      • By (temporarily) setting it to Always, you can see how transparent the dialog will be while moving the slider, which can help prevent making it too transparent to see.
Recommended For You:
Lost Your Data? Here Is How You Can Get It Back By EaseUS

The various action buttons available include:

  • Find Next: Finds the next matching text
    • This checkbox changes the single Find Next button into << and >> buttons, which are “Search backward” and “Search forward” (hovering over this checkbox with the mouse will, after a slight pause in movement, pop up a tooltip indicating “2 find buttons mode”)
  • Count: Counts how many matches are in the entire document, or in the specified direction, or possibly “In Selection”, and shows that count in the message section at the bottom of the dialog box
  • Find All in All Opened Documents: Lists all the search results in a new Find result window; searches through all the file buffers currently open in Notepad++
  • Find All in Current Document: Lists all the search results in a new Find result window; only searches the active document buffer
  • Close: Closes the search dialog
  • Replace: Replaces the currently-selected match. (If no match is currently selected, it behaves like Find Next and just highlights the next match in the specified direction)
  • Replace All: Replaces all matches from the active location onward (following the Backward direction and Wrap around settings as appropriate).
    • NOTE: for regular expressions, this will be equivalent to running the regular expression multiple times, which is not the same as running with the /g global flag enabled that is available in the regular expression engines of some programming-languages.
  • Replace All in All Opened Documents: same as Replace All, but goes through all the documents open in Notepad++, not just the active document.
Recommended For You:
7 Major Differences Between Pigment And Dye Based Ink Cartridges

Basic Guide Of RegEx Usage With Notepad++:

Regex characters can be used to create advanced matching criteria. The following table introduces some of them with practical examples. But before starting make sure that you change the Search Mode from Normal to Regular expression in your Find or Find & Replace dialogue box.

  • [ ]
    The square brackets can be used to match ONE of the multiple characters. For instance, [abc] matches any of the characters a, b or c. Hence, b[eo]n will match words like ben and bon, but not been or beon. Ranges can also be used, [a-z] is any lower case character, and so on.
  • ^
    The caret can be used inside the square brackets to exclude characters from the match. For instance, hell[^o] means the string ‘hell’ will be ignored if followed by the letter ‘o’. Another example is [^A-Za-z] which will exclude all alphabetic characters. However, if not placed inside a set, ^ can be used to matches the start of a line.
  • $
    This matches the end of a line.
  • .
    The period or dot matches any character.
  • \d
    Matches any single digit.
  • \w
    Matches any single alphanumeric characters or underscore.
  • \s
    Matches whitespaces including tabs and line breaks.
  • *
    The asterisk or star sign matches 0 or more times. For example, Ba*m matches Bm , Bam , Baam etc.
  • +
    The plus sign matches 1 or more times. For example, lo+l matches lol , lool , loool etc.
  • \<
    Matches the start of a word. For example, \< directly followed by ‘sh’ matches ‘she’ but does not matches ‘wish’.
  • \>
    Matches the end of a word. For example, sh\> matches ‘wish’ and does not match ‘she’.
  • ( )
    The round brackets can be used in the Find & Replace function to tag a match. tagged matches can then be used in replace with \1, \2 etc.
    For example, If you write 123xxxRRR in the search and 123\1HHH in the ‘Replace with’ filed, the result will be: 123xxxHHH.
  • \
    The backslash can be used to escape regex characters. For example, to match 1+1=2, the correct regex is 1\+1=2. Otherwise, the plus sign will have a special meaning.
Recommended For You:
A Learner’s Guide To Use VBA In PowerPoint 2010

Further, the following two examples should be giving you a better idea of how to use regex in your editor:

  • Find: Win([0-9]+) Replace with: Windows\1
    Will search for strings like Win2000, Win2003 and changes them to Windows2000, Windows2003…
  • Find: [a-z]+(\d\d)\> Replace with: Windows\1
    Will search for all alphanumerics followed by 2 digits only at the end such as Win98 and Win07 and changes them to Windows98, Windows07…

Most Common RegEx For Notepad++:

Regex expression can help you in cleaning your data at ease in a simple and quick way when you want to extract only desired information fro your text. Here are some common RegEx expressions for notepadd++ for your daily use. Feel free to submit more.


This can be done rather quickly in a tool like notepad++ using the find and replace with regular expressions feature.

  1. Go to Find and Replace.
  2. Enter the regular expression.
  3. Select regular expression.
  4. Make sure the cursor is at the start of the document.
  5. Click replace all.

1.) Removing all XML or HTML tags using Notepad++:

  • Find What (Regular Expression): <[^>]+>
  • Replace With: LEAVE BLANK

You Like It, Please Share This Recipe With Your Friends Using...


2 Responses to “A Simple Guide And Most Common RegEx Usage With Notepad++”

  1. SA Arnob says:

    Wow! That’s a Great post for using of notepad. I really appreciate it.Thank you so much for sharing this concept ..

    • EXEIdeas says:

      Welcome here and thanks for reading our article and sharing your view. This will be very helpful to us to let us motivate to provide you more awesome and valuable content from a different mind. Thanks again.

Leave a Reply

Your email address will not be published. Required fields are marked *