Regular expressions

What are they?

They are a way of specifying a pattern of text. Whereas a typical application may enable you to enter a specific string to be matched, an application or language that supports Regular Expressions will enable you describe the range of valid combinations of substrings that result in a match.

What are they good for?

A search for one or more email address’s serves as a good example. The email address: “info@textpression.com” is a simple string, you could just use the Find functionality within your web browser or text editor and locate this string by typing it in. But what if you wanted to locate all email addresses? You could enter the “textpression” part to get all of the Textpression Software addresses, but how to get ANY email address?

The solution is to describe in general terms what you are looking for, rather than simply searching for a fixed string. For our email example we would need to look for the following:

any valid combination of numbers, letters and symbols that comprise the Name part of the email address (e.g. ‘info’), followed by
an ‘@’ symbol, followed by
any valid combination of numbers, letters and symbols that comprise the Domain part of the email address (e.g. ‘textpression’), followed by
a period, followed by
The final combination of letters that comprise the TLD (top level domain) part of the email address (e.g. ‘.com’).

What does a Regular Expression look like?

The exact syntax for Regular Expressions varies slightly according to each language that supports them, however the example below will match a valid email address:

(\w+\.)*\w+@(\w+\.)+[A-Za-z]{2,4}

What do Regular Expressions have to do with Textpression?

By now you’ve no doubt realised just how useful Regular Expressions can be. However they can be a bit daunting for the uninitiated (bare in mind that the example above is for a fairly simple task) and even seasoned pro’s often run into trouble with them.

Textpression enables you to graphically define Regular Expressions in an uncomplicated way. Its simple to use Drag and Drop interface means that you can define expressions without needing to learn and remember any special syntax. Having created an expression, Textpression will automatically convert it for use in a number of supporting languages.

Where can I find out more about Regular Expressions?

For a good general overview visit: Wikipedia’s reference on Regular Expressions