Compartir a través de


Regular Expressions and Operators

Regular expressions are sets of symbols that you can use to create searches for finding and replacing patterns of text. Regular expressions provide a concise and flexible way to specify more complex search and filter criteria against a selection of text than the wildcard character pattern searching available in the Find dialog box.

The following table describes the behavior of regular expression operators in a query.

Operator

Behavior

.

Matches any single character except the newline (\n) character.

*

Matches the preceding character zero or more times. You can also use a question mark (?).

Example   "zo*" matches either "z" or "zoo". The expression "a?ve?" matches the "ve" in "never".

+

Matches the preceding character one or more times.

Example    "zo+" matches "zoo" but not "z".

^

Matches the beginning of the input string.

$

Matches the end of the input string.

[xyz]

Matches any one character in the set. Both opening and closing brackets are required.

Example    "[abc]" matches the "a" in "plain".

[^xyz]

Matches any one character not in the set. Both opening and closing brackets are required.

Example    "[^abc]" matches the "p" in "plain".

[a-z]

Matches any character in the specified range.

Example   "[a-z]" matches any lowercase alphabetic character in the range of "a" through "z".

[^a-z]

Matches any character not in the specified range.

Example   "[^m-z]" matches any character not in the range of "m" through "z".

\

Marks the next character as either a special character such as an escape character or a literal.

Example   "\\" matches "\", and "\(" matches "(".

(pattern)

Matches a pattern group. Both the opening and closing parentheses are required.

Example    "(tress)" matches "mattress" but not "mattres". To match parenthesis characters, use "\(" or "\)".

x|y

Matches either x or y.

Example    "z|wood" matches "z" or "wood". The expression "(z|w)ood" matches "zood" or "wood".

{m}

Matches the preceding character exactly m number of times, where m is nonnegative. Both opening and closing braces are required.

Example    "o{2}" does not match the "o" in "Bob" but matches the first two letter o's in "food" or "foooood".

{m,}

Matches the preceding character at least m number of times, where m is nonnegative.

Example    "o{2,}" does not match the "o" in "Bob" but matches all the o's in "fooooood". In addition, the expression "o{1,}" is equivalent to "o+", and "o{0,}" is equivalent to "o*".

{m,n}

Matches the preceding character at least m and at most n number of times, where both m and n are nonnegative.

Example   "o{1,3}" matches the first three o's in "foooooood". In addition, the expression "o{0,1}" is equivalent to "o?".

All else

Matches itself.

The following rules apply when you use regular expression operators:

  • You can enclose regular expressions in matching quotation marks (" "). You must enclose regular expressions in quotation marks if the expression contains a space or a closing parenthesis ()).

The Regular Expressions Foundation Class provides access to routines for using regular expressions in your applications. For more information, see Regular Expressions Foundation Class.

Visual FoxPro provides a regular expressions sample that you can use to determine how to incorporate regular expression text searching in your application. For more information, see Search Text Using Regular Expressions.

You can refer to MSDN for general details about regular expressions and pattern property matching.

See Also

Reference

Look Up Reference Dialog Box

Find Dialog Box (Visual FoxPro)

Other Resources

General Reference