LATEST >>

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++

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:
Salvaging Ink Cartridges: How To Refill It Perfectly?

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:
Tips For Choosing Headphones For Your Music Devices

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:
Free And Paid Music Composing Apps For Window, Mac And Android Users

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.

How-To-Use-RegEx-With-Notepadd++-Find-And-Replce

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...

20 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.

  2. OFS-INDIA (Video Software Training school) says:

    great information. really appreciate your efforts . keep it up !

    • 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 with more awesome and valuable content from a different mind. Thanks again.

  3. Tarun Nagar says:

    Really you have posted an awesome article. Keep sharing such more articles

    • 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 with more awesome and valuable content from a different mind. Thanks again.

  4. Lee Frates says:

    Awesome Article. Very Informative and well explained.

    • 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 with more awesome and valuable content from a different mind. Thanks again.

  5. Thanks for sharing such a piece of amazing information. Keep posting such awesome articles.

    • 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 with more awesome and valuable content from a different mind. Thanks again..

  6. Jim Witt says:

    Hello, your writing skills are amazing. I have viewed all of your websites and it is truly beautiful. To read the latest blogs, I would love to subscribe to your blog section.

    • 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 with more awesome and valuable content from a different mind. Thanks again.

  7. DC Kumawat says:

    I agree with you that RegEx is a powerful tool that can be used to find and replace text in a variety of ways. It’s important to be aware of the different RegEx syntaxes and to choose the ones that are right for your needs. I think your blog post is a great resource for people who are new to RegEx.

    • 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 with more awesome and valuable content from a different mind. Thanks again. Please contact us via the contact form for more info.

  8. Aaric Evans says:

    You did a great job covering various aspects of Regex. However testing and verifying regex patterns before performing mass replacements is important. It’s recommended to use the “Find” or “Find Next” functionality to ensure that the regex pattern accurately captures the desired text before proceeding with “Replace” or “Replace All.” This step helps prevent unintended changes and ensures the desired results are achieved.

    • 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 with more awesome and valuable content from a different mind. Thanks again.

  9. Wow! That’s a Great post for using of notepad. I really appreciate it.
    Thank you so much for sharing this Amazing 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 with more awesome and valuable content from a different mind. Thanks again.

  10. First of all, I would like to thank you for sharing information about regex with us. I had no idea about regex before reading this post. This tool in the form of Notepad will prove helpful to me.

    • 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 with more awesome and valuable content from a different mind. Thanks again.

Leave a Reply to Saurabh Sharma Cancel reply

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