Regular expressions kit can be run from any tool in the program, which provides the use of regular expressions, such as "Search and Replace", "Fields collector" и "Split articles".
Conditionally window is divided into 3 parts:
- Regular expressions kit
- The regular expression itself and replacement rule (for testing)
- Tester of Regular Expressions
Constructor itself consists of three parts:
- The text that is before what we looking for
- The text itself, which we looking for
- The text that is after what we looking for
In turn, for the text which we search consists of 3 parts: the beginning text, the middle and the termination.
Such division allows to receive convenient quantity of groups for the subsequent replacement. The group is a part of regular expression which is allocated in brackets. It will be most easier to understand about what there is a speech having considered a simple example: it is admissible to us it is necessary to find the text which is in tags «div» and begins with a word «against», and comes to an end with a word to «fight» :
We press the button «Create regular expression» and it is received:
We have 3 groups: opening tag div, the text which begins with Against, and comes to an end to «fight» and closing tag div. We check regular expression:
As we see has coincided precisely as it is necessary for us: has not grasped improper tag in others div's and has not grasped the similar text, but not in tag div.
Now we come back to groups and what for they are necessary: and they are necessary for convenient replacement of the text. For example we want, that the text not in tags «div», and in tags «backquote». For this purpose in the field a replacement Rule we write the following:
The combination \2 will be as a result replaced with the second group of our regular expression (i.e. on the text which begins with Against, and comes to an end to «fight»). Replacement testing will show the following:
As we see have achieved what wanted. If you need to use the first or third group — simply write in proper places \1 or \3 accordingly.
Attention: if the field «Text before always» or «After the text always» is not filled, the program will not allocate it in separate group so groups will be less and their order can will cause a stir that in an example. As the program never allocates this text in separate group if to start the designer not for tool «Replacement».