Home » Support » Tutorials/Power Tips » UltraEdit » Perl-style regular expressions for function strings
IDM Power Tips

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.

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

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

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

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

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.

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


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]*)"

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

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.

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


Back to power tips index

Cnet/Download.com
"We won't mince words:
UltraEdit is outstanding..."

Corporate Licensing

It's easy to purchase corporate licensing from us!

  • Bulk/quantity discounts
  • Enterprise/plant/site licensing
  • Purchase with PO or invoice

The new UltraSuite

The only fully integrated solution of its kind!

Four powerful applications: UltraEdit, UltraCompare, UltraFinder, and UltraSentry!

Save over 33% when you bundle with the UltraSuite!

Power of Portable

Now supporting PortableApps!

UE/UC Mobile

Unleash the power of the total file management solution on your flash drive!