SincpacC3D General Information Command Summary Quux Software

Regular Expressions

The option for "Use Regular Expression" is very powerful. With a normal search, the Find string must exactly match the text in the Raw Description. However, when "Use Regular Expression" is checked, both the Find and Replace strings are treated as Regular Expressions.

There are many options in Regular Expressions. For the most part, the characters in a Regular Expression are literal characters to match - the letter "a" matches the letter "a", and so forth. However, some characters in Regular Expressions have special meanings.

Some of the most-useful features of regular expressions are described here. However, Regular Expressions are a rather rich subject, and more information on them can be found by searching the web.

Character Escapes

Character Escapes are indicated using the Backslash ("\"). A Character Escape is simply a way of using normal letters to specify special characters. Some of the most-useful Character Escapes are in the table below:

Character Escape

Description

\t

Tab character.

\040

ASCII code in octal.

\x20

ASCII code in hexadecimal

\u0020

Matches a Unicode character string.

\\

Matches a literal backslash.

Character Classes

Character Classes indicate a set of characters. A Character Class will match any of the characters in its component set.

Character Class

Description

.

Matches any character except \n (newline).

[aeiou]

Matches any single character in the specified group. The example to the left would match any of the vowels (a, e, i, o, or u). A hyphen may also be used to specify a contiguous range of characters, e.g. [a-z] specifies all lowercase letters from a to z.

[^aeiou]

Matches any single character EXCEPT for those in the specified group. The example to the left would match any character EXCEPT for one of the vowels (a, e, i, o, or u). Hyphens may also be used to specify a contiguous range of characters.

^

Matches the start of the string the pattern is being applied to.

$

Matches the end of the string the pattern is being applied to.

\w

Matches any word character. The same as [a-zA-Z_0-9].

\W

Matches any character that is NOT a word character. The same as [^a-zA-Z_0-9].

\d

Matches any numerical digit. The same as [0-9].

\D

Matches any character that is NOT a numerical digit. The same as [^0-9].

\s

Matches any whitespace character (tabs, spaces, etc.).

\S

Matches any non-whitespace character.

\b

A word boundary, i.e. the transition between \w and \W characters. (May also indicate a backspace in certain cases.)

Quantifiers

Quantifiers indicate how many occurrences of the preceding character can be matched. For new-comers to Regular Expressions, one of their most-confusing aspects is that the asterisk (*) is a Quantifier in a Regular Expression, and not a wildcard. The difference can be seen in the Examples later in this page.

Some of the most-useful Character Escapes are in the table below:

Quantifier

Description

?

Matches either 0 or 1 occurrences of the preceding character. Basically, makes the preceding character optional in the match.

+

Matches 1 or more occurrences of the preceding character. Will match as many characters as possible.

+?

Matches 1 or more occurrences of the preceding character. Will match as few characters as possible.

*

Matches 0 or more occurrences of the preceding character. Will match as many characters as possible.

*?

Matches 0 or more occurrences of the preceding character. Will match as few characters as possible.

These quantifiers are processed from left to right. This is usually only important when using grouping characters. See the sample regular expressions at the end of this page for some examples of this.

Grouping and Back References

It is also possible to create a group out of a portion of a Regular Expression, and then refer to that group later. A Group is created by using parentheses to indicate the limits of the group. Multiple groups may be declared in the same Regular Expression.

These Groups may then be referenced in the replacement string by using $1 to refer to the first one, $2 to refer to the second, $3 for the third, etc., through $9. See the end of the Sample Regular Expressions for some examples of how grouping works.

Sample Regular Expressions

Find String

Replace String

Sample Input and Output

ABC

XYZ

AB

AB

ABC

XYZ

ABCDEF

XYZDEF

ABCCCC

XYZCCC

ABCCCCDEF

XYZCCCDEF

ABDEF

ABDEF

ABC?

XYZ

AB

XYZ

ABC

XYZ

ABCDEF

XYZDEF

ABCCCC

XYZCCC

ABCCCCDEF

XYZCCCDEF

ABDEF

XYZDEF

ABC+

XYZ

AB

AB

ABC

XYZ

ABCDEF

XYZDEF

ABCCCC

XYZ

ABCCCCDEF

XYZDEF

ABDEF

ABDEF

ABC*

XYZ

AB

XYZ

ABC

XYZ

ABCDEF

XYZDEF

ABCCCC

XYZ

ABCCCCDEF

XYZDEF

ABDEF

XYZDEF

ABC.+

XYZ

AB

AB

ABC

ABC

ABCDEF

XYZ

ABCCCC

XYZ

ABCCCCDEF

XYZ

ABDEF

ABDEF

ABC.*

XYZ

AB

AB

ABC

XYZ

ABCDEF

XYZ

ABCCCC

XYZ

ABCCCCDEF

XYZ

ABDEF

ABDEF

^ABC

XYZ

ABC

XYZ

ABCDEF

XYZDEF

DEFABC

DEFABC

ABC$

XYZ

ABC

XYZ

ABCDEF

ABCDEF

DEFABC

DEFXYZ

(.+)\W+(.+)

$2 $1

ABC

ABC

ABC XYZ

XYZ ABC

ABC MNO XYZ

XYZ ABC MNO

(.+?)\W+(.+)

$2 $1

ABC

ABC

ABC XYZ

XYZ ABC

ABC MNO XYZ

MNO XYZ ABC