Using Regular Expressions

Reference:

Some FOCUS features accept regular expressions as input.

A regular expression is a string containing a tagged expression. A tagged expression is a portion of the string that contains a pattern that will be matched against an actual character string.

This section summarizes how to create a regular expression. More information about regular expressions can be found on the Web.

Reference: Summary of Regular Expressions

Tagged expressions must be enclosed in parentheses. The backslash character (\) is a special character in tagged expressions. If a group ID actually contains a backslash character, you indicate that you want the backslash character to be treated as a normal character by entering two successive backslash characters (\\).

The following can be used to create the tagged expression:

abc

Matches abc anywhere within the string.

(abc)

Matches abc anywhere within the string, but the parentheses act as a tag.

[]

Defines a character class (or set) that matches any one of the characters in the class. For example, [abc] matches the character a or b or c. The expression [x-y] matches any character from x to y.

.

Matches any single character except newline.

\w

Matches any word character string (alphanumeric plus "_").

\W

Matches any non-word character.

\s

Matches any whitespace character.

\S

Matches any non-whitespace character.

\d

Matches any digit.

\D

Matches any non-digit character.

\t

Matches a tab character.

\r

Matches a return character.

\f

Matches a formfeed character.

\e

Matches an escape character.

\b

Matches a word boundary or a backspace. For example, test\b matches test, but not testing. However, \b matches a backspace character when specified inside a class (that is, [\b]).

\B

Requires that there is no word boundary. hello\B matches hello, but not hello there.

^

Matches characters only at the beginning of the string. For example, ^abc matches abc at the beginning of the string.

$

Matches characters only at the end of the string. For example, abc$ matches abc at the end of the string.

|

Specifies alternative matching characters. For example, a|b matches either a or b. This metacharacter can also be used with words, for example, abc|def.

[^abc]

Matches a character that is not in the set. [^abc ]+ will match such strings as hello, test, and perl.

\

Is the escape character. For example, \* matches the * character. Use the backslash (\) character to escape (remove the special meaning of) characters that have significance in a regular expression.

(?i)

Ignores case. For example, (a(?i)b|c) matches aB, c, and C.

You can follow any character, wildcard, or series of characters and/or wildcards with a repetition indicator:

*

Matches 0 or more occurrences of the character sequence.

+

Matches 1 or 0 occurrences of the character sequence.

?

Matches 0 or more occurrences of the character sequence or the shortest match.

{}

Is the repetition modifier.

{n}

Matches exactly n occurrences of the character sequence.

{n,}

Matches at least n occurrences of the character sequence.

{n,m}

Matches at least n but not more than m occurrences of the character sequence.


Information Builders