Komodo Editor Regular Expressions

What is a regular Expression

Regular expressions, or regexes for short, are a way to match text with patterns. They are a powerful way to find and replace strings that take a defined format. For example, regular expressions can be used to find and replace any class or id in HTML source. They can also be useful in reformatting data files that you want to import into Excel.

Identifying a set of characters

It is common to want to find a string of characters or numbers in a file. For example, you may want to find all the class aattributes, regardless of which class it is. In a data file, you may want to get rid of all of the new line characters except those that precede a character string.

To identify a set of characters that are to be used in a regular expression, we enclose the list in []. For example, if we wanted to find either an "a" or a "b", we would write

[ab]

In general, we are looking for more characters than one or two. If you are looking for a range, you can write it simply using a dash. For example [0-9] represents any digit. There are a number of shorthand notations that can be used to refer to common classes of letters.

Multiplicity

If you want to match 0 or more of the characters, follow the square brackets with a *. For one or more, use a +

Of particular value, is the following expression that matches a string of one or more characters, including special characters:

[\w\s\d\W\D]+

Setting up the Replace

When you open the Replace dialogue box, there are anumber of check boxes along the bottom. A number of these settings are critical