IDM PowerTips

Enabling perl-style regular expressions for function strings

UltraEdit allows you to use Perl-style regular expressions to define functions in the wordfile for the function list when syntax highlighting is in use. Enabling this is very simple. The steps below will guide you through the process of enabling Perl-style regular expressions for your function strings in your wordfile.

Syntax highlighting is defined by the wordfile in the syntax highlighting options of the advanced configuration. You will need to open and edit the wordfile in order to enable this.

Enabling Perl-Style Regular Expressions in the Wordfile for Function Strings

For our example, we would like to add a Perl-style regex function string to our Visual Basic language definition. The expression will find the occurrences of “TODO:” and “FIXME:” that are contained in line comments, in the Visual Basic source code, and display them in the function list.

Step 1: Locate and open the wordfile

You can see where your default wordfile is located by navigating to Advanced : Configuration : Editor Display : Syntax Highlighting. Click the “Open” button to open the wordfile UltraEdit is using.

Once you’ve opened your wordfile, you will need to locate the language for which you’d like to add Perl-style regex function strings.

Each language definition starts with:

/Lx”Language Name”

Where x has a value of 1 to 20 and “language name” is the language name.

For our example, as we previously mentioned, we are going to add a Perl-style regex function string to the Visual Basic language definition for “TODO” and “FIXME” items.

With the wordfile open, you can press CTRL + F to do a search for the language definition within the wordfile. For our example we will search for “Visual Basic”, which should take us to the Visual Basic language definition.

Step 2: Define the Perl-style regular expression type in the wordfile

Now that you’ve located the correct language in the wordfile, you will need to enter the following string at the top of the language definition to enable the Perl-style function string regex:

/Regexp Type = Perl

This is the “key” to enabling Perl-style regex function strings.

Step 3: Create the function string

The next step is to find the Perl Compatible expression for the function string.

You will need to create your Perl-style regular expression using the Perl-style regular expression syntax. If you are unfamiliar with Perl-style regular expressions syntax, see “Regular Expressions (Perl Style) ” in the application’s Help file.

After creating your expression, the best way to test it is to do a FIND (CTRL + F), with “Regular Expressions” enabled in the FIND dialog, on a sample file of your source code. If the “function” is not matched edit your expression appropriately until it matches the functions you expect it to.

You can see in the below screenshot what Perl-style regular expression was used to find the “TODO” (or “FIXME”) item in the Visual Basic file.

Step 4: Tag the function in the regex, and insert it into your wordfile.

After you have created an expression that matches the desired text, you will want to “tag” the text that you wish to populate the function list with. The text that is found between the parenthesis () will be displayed in the function list.

Using our example, we will place the tags around the text including the TODO or FIXME to the end of the line, but exclude the line comment character.

/Function String 1 = “((TODO:|FIXME:)[ \t]*[\w\d \t]*)”

After you have created the expression string you will need to paste it into the wordfile.

You can define up to 5 function strings; in other words, you can create a new function string in the form of the following:

/Function String 1 = “..regular expression..”

/Function String 5 = “..regular expression..”

Finally, save and close your wordfile. This is all it takes! Your function list will now be populated based upon the Perl-style regex you defined in the wordfile. As you can see in the below screenshot, our “TODO” item now appears in the function list for the syntax-highlighted Visual Basic file.