Regular expressions

Special metacharacters and sequences are used in writing patterns for regular expressions. The following table describes some of these characters and includes short examples showing how the characters are used. Another recommended resource is the Regular Expression Library at http://regexlib.com/Default.aspx.

Tip: To verify the syntax of regular expressions you create, use the Regular Expression Editor (if it is installed on your system).

Character

Description

\

Marks the next character as special. /n/ matches the character " n ". The sequence /\n/ matches a line feed or newline character.

^

Matches the beginning of input or line.

Also used with character classes as a negation character. For example, to exclude everything in the content directory except /content/en and /content/ca, use: /content/[^(en|ca)].*/.* . Also see \S \D \W.

$

Matches the end of input or line.

*

Matches the preceding character zero or more times. /zo*/ matches either " z " or "zoo."

+

Matches the preceding character one or more times. /zo+/ matches "zoo" but not "z."

?

Matches the preceding character zero or one time. /a?ve?/ matches the "ve" in "never."

.

Matches any single character except a newline character.

[xyz]

A character set. Matches any one of the enclosed characters. /[abc]/ matches the "a" in "plain."

\b

Matches a word boundary, such as a space. /ea*r\b/ matches the "er" in "never early."

\B

Matches a nonword boundary. /ea*r\B/ matches the "ear" in "never early."

\d

Matches a digit character. Equivalent to [0-9].

\D

Matches a nondigit character. Equivalent to [^0-9].

\f

Matches a form-feed character.

\n

Matches a line feed character.

\r

Matches a carriage return character.

\s

Matches any white space including space, tab, form-feed, and so on. Equivalent to [ \f\n\r\t\v]

\S

Matches any nonwhite space character. Equivalent to [^ \f\n\r\t\v]

\w

Matches any word character including underscore. Equivalent to [A-Za-z0-9_].

\W

Matches any nonword character. Equivalent to [^A-Za-z0-9_].

OpenText DAST engineers have also created and implemented extensions to the normal regular expression syntax. For more information, see Regex extensions.