Perl ProgrammingLearn to use Regex Editor Tool in Perl Programming

Learn to use Regex Editor Tool in Perl Programming

Perl--editinf-tool

After installing the Padre IDE, and using it to write and run Perl scripts, we will investigate the Regex Editor tool, which is built in the Padre software, to write and test regular expression patterns. That will be the subject of today’s article. Another light article to read, so have a nice reading.

Starting the Regex Editor

The tool can be started from the Tools menu à Regex Editor.

1

This will open the Regex Editor window.
2

Using Regex Editor to Write and Test Patterns
In its basic shape, the Regex Editor window contains three text boxes: one for the search pattern, another for the text to match against the regular expression (original text), and a third for the matched text.

On the top of the window, there are five check boxes to enable/disable the following search options:

  • Ignoring the letter case (i).
  • Single-line matching (s).
  • Multi-line matching (m).
  • Extended regular expressions (x).
  • Global Search (g).

3

On the right, there are six buttons.
4

These buttons could be used to insert character classes, quantifiers, escape characters, and anchors.

Example
We want to search the quote “Be the change that you wish to see in the world.” for any occurrence of the word “The”.

First: in the Original Text textbox, type the above string. Next, write the search pattern (literal The) in the Regular Expression textbox. This should give No Match.
5

If you check the Ignore Case (i) checkbox, this will cause the sentence to be matched.
6

Creating a Bit More Complicated Patterns
Now, we need to create a pattern that matches Capital A in the beginning of the line.

First, click the Miscellaneous button, then click ^ Beginning of line.
7

This will insert the caret ^ in the Regular Expression textbox. Then, write the uppercase letter A. This should match a name like “Alessandro Del Piero”.
8

On the other hand, a name like “Raul Gonzalez” will not match that pattern.
9

Learn the Basics of C Programming Language

Substituting a Matched Text
To use the substitution feature of the Regex Editor, check the Show Substitution checkbox. This will show two additional textboxes: Replace text with, and Result from replace.
10

Example
We need to replace each “the” in the quote “The whole world steps aside for the man who knows where he is going.” with “THE”, ignoring case.

Okay, ignoring case means using the i option, and replacing all matches requires the global substitution (the g option).
11

Inserting the Written Pattern into Perl Code
When you are done with the pattern you are writing, you can ask Regex Editor to insert it into your Perl code. This is done using the Insert button.
12

Summary
In this article, we have learned how to use the Regex Editor tool to write and test regular expression patterns. I hope you enjoyed reading. See you.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exclusive content

- Advertisement -

Latest article

21,501FansLike
4,106FollowersFollow
106,000SubscribersSubscribe

More article

- Advertisement -