Applying Expert Notepad Regular Expressions

Applying Expert Notepad Regular Expressions


The expert style of programming and the use of working tools and programs is distinguished by the use of special techniques, such as the regular expression of an expert's notebook, which greatly increase the efficiency of work.

Most of the programming of the code is painstaking and monotonous work, often performing the same type of actions, as well as finding and replacing, both single characters and whole expressions.

These (regular) expressions were created specifically to speed up and simplify the search for certain elements in a document for certain conditions. In the popular programmer's tool, the Notepad ++ editor, it is possible to create your own and use ready-made expressions. At the same time, the user moves to a more advanced, efficient level of work both with Notepad ++ and with writing code in general.

What are regular expressions

Before proceeding directly to using the expression system in Notepad ++, it is necessary to clarify what it is. This term denotes a specific search language designed to perform advanced search and replace and perform other actions on strings of a document.

Notepad regular expressions are designed to search and replace text in a line, file, or several files. They are used by developers in application code, testers in autotests, and also when working on the command line. In Analytics, a regular expression is a sequence of characters that more or less broadly matches Google Analytics data patterns.

The principle of operation of these expressions is based on the use of special metacharacters that make up the template, according to which the action is performed on the lines of the document.

An example is the following construction [A-Z], which means any capital letter written in Latin. And, a dot, means any of the possible symbols at all.

Depending on the peculiarities of a particular programming language, the syntax for writing reg. expressions can be different. For the Notepad ++ editor, reg. expressions written in Perl (one of the popular programming languages).

General familiarity with regular expressions in Notepad ++

Let's present the basic regular expressions that can be used in Notepad ++:

  • ... - each character (one);
  • [0-9] - each character (number);
  • \ D - every alphabetic character;
  • [A-Z] - each capital letter in Latin;
  • [a-z] - each lowercase letter of the Latin spelling;
  • [a-Z] - each of the Latin letters in any case;
  • \ w - alphabetic, underscore, or numeric character;
  • \ s - space;
  • ^ - search for the beginning of a line;
  • $ - line termination designation;
  • - the symbol can be repeated an infinite number of times;
  • \ 4 \ 1 \ 2 \ 3 - designation of the group in numerical order;
  • ^ \ s * $ - empty lines are searched;
  • ([0-9] [0-9] *.) - two-digit numbers are searched.

These are just some of the most common line-by-line searches in a document. In fact, reg. There are many more expressions and their variations used in Notepad ++. This is a whole interesting topic that requires a separate study.

Programmers who have learned to apply reg. expressions in practice have the advantage of performance and competitiveness.

How to practically apply regular expressions in Notepad ++

Now let's look at practical examples of using reg. expressions in Notepad ++.

1. Organization of search

To start the search procedure, go to the Search menu item and then the Find item. The keyboard shortcut to go to the Notepad ++ search window is Ctrl + F.

Attention! It is necessary to activate the button Regular expressions to be able to work in this format.

To find all the digital characters contained in the document, just enter the construction [0-9] into the search string and search for Search next.

Thus, each click on this button will find and highlight the next digit in the document.

Become an Excel Pro: Join Our Course!

Elevate your skills from novice to hero with our Excel 365 Basics course, designed to make you proficient in just a few sessions.

Enroll Here

Elevate your skills from novice to hero with our Excel 365 Basics course, designed to make you proficient in just a few sessions.

The mode when the search is carried out in reverse order (from bottom to top) with reg. expressions does not work.

If you use the Find All button, the results will be displayed in a separate window.

2. Organization of replacement

With the help of reg. expressions in Notepad ++, you can not only search, but also replace certain characters that meet the specified conditions.

To do this, just go to the Replace window of the search window.

Let's say we need to redirect links using a redirect. To perform this action, in the Find line, substitute the following construction: href =. (Http: // [^ '] *) , and, accordingly, in the Replace line, specify: href = / redirection.php? To = 123 ″ . After clicking on the Replace all button, the replacement procedure is performed automatically in all elements that match the conditions.

In addition, in Notepad ++ using reg. expressions, you can perform similar operations with documents not related to programming or the development of sites and applications.

Let's say you have a list of employees with full names and birthdays. In this simple example, we will swap the name and date of birth. To do this, in the Find field, specify (\ w +) (\ w +) (\ w +) (\ d +. \ D +. \ D +), and, accordingly, in the Replace field, specify \ 4 \ 1 \ 2 \ 3 . After clicking on the Replace All button, you can see the result of a successful operation.

Macros and their application in Notepad ++

We have considered the simplest operations with reg. expressions in Notepad ++. Programmers working at the expert level solve rather complex problems using these expressions.

The concept of a notepad macro is, in fact, a piece of code that can be inserted into a specific place in a document with one click. Macros are a kind of templates that you can write yourself when performing any actions in this program.

Macros are capable of solving many monotonous and similar tasks. They are written by programmers both for a single project and for widespread use. As a rule, each programmer has his own set of macros to simplify work on typical projects.

Macro recording is performed from the main toolbar, using the Start recording button. The macro will record everything that happens to the document while the recording is in progress.

Read more detailed information on this issue before starting work!

More Notepad++ tips and tricks


Become an Excel Pro: Join Our Course!

Elevate your skills from novice to hero with our Excel 365 Basics course, designed to make you proficient in just a few sessions.

Enroll Here

Elevate your skills from novice to hero with our Excel 365 Basics course, designed to make you proficient in just a few sessions.



Comments (0)

Leave a comment