Please accept our apologies – due to high winds in the area, IDM is experiencing service outages and cannot currently receive phone calls. If you're trying to reach our sales team, please be sure to send us an email.

Home » Support » Tutorials/Power Tips » UltraEdit » Regular expressions

IDM PowerTips

Regular expressions

Regular Expressions are essentially patterns rather than specific strings that are used with Find/Replace operations. There are many ways that regular expressions may be used to streamline operations and enhance efficiency. We have listed below a reference key for both UltraEdit-style and UNIX-style regular expressions as well as some examples to demonstrate how regular expressions may be used in UltraEdit.

Regular Expressions in UltraEdit
UltraEdit SymbolUNIX SymbolFunction
%^Matches/anchors the beginning of line.
$$Matches/anchors the end of line.
?.Matches any single character except a newline character. Does not match repeated newlines.
* Matches any number of occurrences of any character except newline.
++Matches one or more of the preceding character/expression. At least one occurrence of the character must be found. Does not match repeated newlines.
++*Matches the preceding character/expression zero or more times. Does not match repeated newlines.
^\Indicates the next character has a special meaning. "n" on its own matches the character "n". "^n" (UE expressions) or "\n" (UNIX expressions) matches a linefeed or newline character. See examples below.
[ ][ ]Matches any single character or range in the brackets.
[~xyz][^xyz]A negative character set. Matches any characters NOT between brackets.
^b\fMatches a page break/form feed character.
^p\pMatches a newline (CR/LF) (paragraph) (DOS Files).
^r\rMatches a newline (CR Only) (paragraph) (MAC Files).
^n\nMatches a newline (LF Only) (paragraph) (UNIX Files).
^t\tMatches a tab character.
[0-9]\dMatches a digit character.
[~0-9]\DMatches a non-digit character.
[ ^t^b]\sMatches any white space including space, tab, form feed, etc., but not newline.
[~ ^t^b]\SMatches any non-white space character but not newline.
\vMatches a vertical tab character.
[0-9a-z_]\wMatches any alphanumeric character including underscore.
[~0-9a-z_]\WMatches any character except alphanumeric characters and underscore.
^{A^}^{B^}(A|B)Matches expression A OR B.
^\Overrides the following regular expression character.
^(...^)(...)Brackets or tags an expression to use in the replace command. A regular expression may have up to 9 tagged expressions, numbered according to their order in the regular expression.
^1\1Numerical reference to tagged expressions. Text matched with tagged expressions may be used in Replace commands with this format.
Note: ^ refers to the character '^' NOT Control Key + value.


UltraEdit/UNIX Regular Expression Examples


Simple String Matching

Simple string matching is probably the most basic form of regular expressions but can allow you to quickly exploit different patterns so that you can search for more than one string at a time rather than doing multiple Find operations.

UltraEdit RegExp:

Find What: m?n
Matches: "man" and "men" but not "moon"

Find What: t*t
Matches: "test", "tonight" and "tea time" (the "tea t" portion) but not "tea
time" (newline between "tea " and "time").

Find What: Te+st
Matches: "test", "teest", "teeeest", etc. but does not match "tst"

UNIX RegExp:

Find What: m.n
Matches: "man" and "men" but not "moon"

Find What: t.*t
Matches: "test", "tonight" and "tea time" (the "tea t" portion) but not "tea
time" (newline between "tea " and "time").

Find What: Te+st
Matches: "test", "teest", "teeeest", etc. but does not match "tst"

Back to top


Character Sets

A character set is a group of characters bounded by "[" and "]". These may be used to designate specific characters to be matched or ranges (i.e. [aeud], or [a-z]).

UltraEdit RegExp:

Find What: [aeiou]
Matches: every vowel

NOTE: Regular Expressions in UltraEdit are not case-sensitive unless Match Case is selected in the Find dialog.

Find What: [,.^?]
Matches: a literal ",", "." or "?".

Because the "?" is a symbol used in expressions it must be "escaped" for the literal character to be matched rather than interpreted as an expression.

Find What: [0-9a-z]
Matches: any digit or letter

Find What: [~0-9]
Matches: any character except a digit (~ means NOT the following)

UNIX RegExp:

Find What: [aeiou]
Matches: every vowel

Find What: [,\.?]
Matches: a literal ",", "." or "?".

Because the "." is a symbol used in expressions it must be "escaped" for the literal character to be matched rather than interpreted as an expression.

Find What: [0-9a-z]
Matches: any digit or letter

Find What: [^0-9]
Matches: any character except a digit (^ means NOT the following)

Back to top


OR Expressions

Currently UltraEdit only allows for the specification of two operands for an OR expression. You may search for an expression A or B as follows:

UltraEdit RegExp:

Find What: ^{John^}^{Tom^}

UNIX RegExp:

Find What: (John|Tom)

There should be nothing between the two expressions. You may combine A or B and C or D in the same search as follows:

UltraEdit RegExp:

Find What: ^{John^}^{Tom^} ^{Smith^}^{Jones^}

UNIX RegExp:

Find What: (John|Tom) (Smith|Jone)

This will search for "John" or "Tom" followed by "Smith" or "Jones".

Back to top


Deleting Blank Lines

With Regular Expressions selected in the Replace dialog this will match the a CR/LF (DOS line terminator) immediately followed by the end of a line (i.e., a blank line) and replace it with nothing, effectively deleting it:

UltraEdit RegExp:

Find What: ^p$
Replace With: (literally nothing)

UNIX RegExp:

Find What: \p$
Replace With: (literally nothing)

Back to top


Reformatting Text With Tagged Expressions

Example 1:

Tagged expressions may be used to mark various data members so that they may be reorganized, reformatting the data. For example, it might be useful to be able to rearrange:

John Smith, 385 Central Ave., Cincinnati, OH, 45238

into:

45238, Smith, John, 385 Central Ave., Cincinnati, OH

UltraEdit RegExp:

Find What: %^([a-z]+^) ^([a-z]+^), ^(*^), ^(*^), ^(*^), ^([0-9]+^)
Replace With: ^6, ^2, ^1, ^3, ^4, ^5

UNIX RegExp:

Find What: ^([a-z]+) ([a-z]+), (.*), (.*), (.*), ([0-9]+)
Replace With: \6, \2, \1, \3, \4, \5

Back to top

Example 2:

If you have a web-based registration system it might be useful to rearrange the order data into a format easily used by a database:

name = John Smith
address1 = 385 Central Ave.
address2 =
city = Cincinnati
state = OH
zip = 45238

into:

John Smith, 385 Central Ave.,, Cincinnati, OH, 45238,

This can be done with the following expression:

UltraEdit RegExp:

Find What: name = ^([a-z ]+^)^paddress1 = ^([a-z 0-9.,]+^)^paddress2 = ^([a-z 0-9.,]++^)^pcity = ^([a-z]+^)^pstate = ^([a-z]+^)^pzip = ^([0-9^-]+^)
Replace With:^1, ^2, ^3, ^4, ^5, ^6

UNIX RegExp:

Find What: name = ([a-z ]+)\paddress1 = ([a-z 0-9.,]+)\paddress2 = ([a-z 0-9.,]*)\pcity = ([a-z]+)\pstate = ([a-z]+)\pzip = ([0-9^-]+)
Replace With:\1, \2, \3, \4, \5, \6