Regular Expressions
When you select classes, objects or items using a name pattern, you can use regular expressions. Regular expressions are text patterns that are used for string matching. Regular expressions are strings that contain a mix of plain text and special characters to indicate what kind of matching to do.
Suppose we are looking for a numeric digit, then the regular expression we would search for is "[0-9]". The brackets indicate that the character being compared should match any one of the characters enclosed within the bracket. The dash (-) between 0 and 9 indicates that it is a range from 0 to 9. Therefore, this regular expression will match any character between 0 and 9, that is, any digit. If we want to search for a special character literally we must use a backslash before the special character. For example, the single character regular expression "\*" matches a single asterisk. In the table below the special characters are briefly described.
Character | Description |
---|---|
^ |
Beginning of the string. The expression "^A" will match an A only at the beginning of the string. |
^ |
The caret (^) immediately following the left-bracket ([) has a different meaning. It is used to exclude the remaining characters within brackets from matching the target string. For example, [^abc] matches any character other than "a", "b", or "c". [^a-z] matches any single character that is not a lowercase letter from "a" to "z". The expression "[^0-9]" indicates that the target character should not be a digit. As above, literal characters and ranges can be mixed. |
$ |
Matches the ending position of the string. |
. |
The dot (.) matches any single character. Within bracket expressions, the dot character matches a literal dot. For example, a.c matches "abc", etc., but [a.c] matches only "a", ".", or "c". |
* |
The asterisk (*) indicates that the character to the left of the asterisk in the expression should match 0 or more times. |
? |
Matches the preceding element zero or one time. For example, ba? matches "b" or "ba". |
+ |
The plus (+) matches the preceding element one or more times. It is similar to asterisk but there should be at least one match of the character to the left of the + sign in the expression. For example, ba+ matches "ba", "baa", "baaa", and so on. |
() |
The parenthesis affects the order of pattern evaluation and also serves as a tagged expression that can be used when replacing the matched sub-string with another expression. |
[] |
Brackets ([ and ]) enclosing a set of characters indicates that any of the enclosed characters may match the target character. For example, [abc] matches "a", "b", or "c". [a-z] specifies a range which matches any lowercase letter from "a" to "z". These forms can be mixed: [abcx-z] matches "a", "b", "c", "x", "y", or "z", as does [a-cx-z]. The - character is treated as a literal character if it is the last or the first (after the ^) character within the brackets: [abc-], [-abc]. Note that backslash escapes are not allowed. The ] character can be included in a bracket expression if it is the first (after the ^) character: []abc]. |
| |
The choice (aka alternation or set union) operator matches either the expression before or the expression after the operator. For example, abc|def matches "abc" or "def". |
Probably the most important special characters for IPSEpro users are the ^ and the $, which match the beginning and the end of a name, respectively.
While the pattern “GT_” matches any name that contains the pattern “GT_” (for example “ST_AND_GT_GENERATOR”), the pattern “^GT_” only matches names with a “GT_” prefix, like “GT_GENERATOR”.
Patterns are case sensitive. |