Previous Next

Introducing Quest Reporter : Appendix B: Attributes and Regular Expressions : Basic Regular Expression Syntax

Basic Regular Expression Syntax
A regular expression consists of a specified set of strings that are used for matching criteria during searches.
Regular expressions can contain both special and ordinary characters. Most ordinary characters, like "A", "a", or "0", are the simplest regular expressions; they match themselves. You can concatenate ordinary characters, so last matches the string 'last'.
The following table provides a list of regular expressions:
.
*
+
?
"(?!dmin\$)" searches forward from current position in the sequence of characters to match "dmin$"; if found, this is a negative match and "dmin$" is exempted as a match.
"(?<!c)" searches backward from current position in the sequence of characters to match "c"; if found, this is a negative match and "c" is exempted as a match.
"r[aeiou]t" matches "rat", "ret", "rot", "rut" since "r- followed by one character from the set of vowels followed by t".
Any character not in the set. This regular expression negates the set—the character must match any character not within the set. This is a useful way of specifying a large set of characters, for instance, consonants are "not vowels".
"t[^aeiou]+.*s" matches "thanks", "this" since "t- followed by one or more of any character which is not a vowel followed by zero or more of any character followed by an s".
^
$
\
To show the use of expressions, consider a couple of real-world scenarios.
Example 1: Specific Search with Inclusions and Single Exclusion
In this example, the administrator wanted to include shares that started with A through F including lowercase characters while excluding the admin$ share from the search.
The syntax for this set of expressions is as follows:
^[a-fA-F](?!dmin\$)[ \w\$]*
The first expression in this set, "^[a-fA-F]", starts the search at the beginning of the data string and searches for shares that start with "a", "b", "c", "d", "e", "f", "A", "B", "C", "D", "E", or "F". The next expression, "(?!dmin\$)", looks for the admin share to be excluded since the "!" character represents a negative match. The final expression, "[ \w\$]*", continues the entire process until the end of line is reached, or the end of the string is reached, or a white space or word is encountered.
The syntax details are as follows:
Example 2: Specific Search with Inclusions and Multiple Exclusions
This example is very similar to the first example, but includes an additional exclusion. In this example, the administrator wanted to include shares that started with A through F including lowercase characters while excluding the admin$ and C$ share from the search.
The syntax for this set of expressions is:
^[a-fA-F](?!dmin\$)(?<!c)[ \w\$]*
The first expression in this set, "^[a-fA-F]", starts the search at the beginning of the data string and searches for shares that start with "a", "b", "c", "d", "e", "f", "A", "B", "C", "D", "E", or "F". The next expression, "(?!dmin\$)", looks for the admin share to be excluded since the"!" character represents a negative match. The third expression, "(?<!c)", searches backward from the current location in the string for any share starting with "c" and excludes it. The final expression, "[ \w\$]*", continues the entire process until the end of line is reached, or the end of the string is reached, or a white space or word is encountered.
The syntax details are as follows:
This example uses specific exclusion, in that within the matches found, it then checks for and excludes shares starting with "c". Additional exemptions must each be specified with their own expression, for example, adding "(?<!B)" to this set of expressions would also exclude any share starting with B.