A regular expression is a string that is used to describe or match a set of strings, according to certain syntax rules. They are usually used to give a concise description of a set, without having to list all elements. For example, the set containing the three strings Handel, Händel, and Haendel can be described by the pattern "H(ä|ae?)ndel" (or alternatively, it is said that the pattern matches each of the three strings).
Character |
Meaning |
Example |
^ |
Matches the start of the line (or any line, when applied in multiline mode) |
^B - This pattern matches any line that starts with "B" character |
$ |
Matches the end of the line (or any line, when applied in multiline mode) |
X$ - This pattern matches any line that ends with "X" character |
. |
Matches any single character except new line character "\n" |
i.ation - This pattern specifies any word starting with "i" followed by any single character and finished by "ation" substring ( for example "isation", "ization") |
* |
A single character expression followed by "*" matches zero or more copies of the expression |
ra*t - This pattern specifies any word started with "r" and ended by "t" where "a" character can appear 0 or more times starting from the 2-nd position ( for example "rt", "rat"," raat", etc.) |
+ |
The previous character can be repeated 1 or more times |
ra+t - This pattern specifies any word started with "r" and ended by "t" where "a" character can appear 1 or more times starting from the 2-nd position ("rat", "raat", "raaat", etc.) |
? |
The previous character can be repeated 0 or 1 time |
ra?t - This pattern specifies only one of the following: "rt" or "rat" |
\s |
Any space character |
\sa - This pattern specifies the "a" character preceded by [space] character |
\S |
Any non-space character |
\SF - This pattern specifies the "F" character preceded by any non-space character ( for example"aF", "rF", "cF" but not [space]F ) |
\b |
The character representing the word boundary |
ion\b - This pattern specifies any word that is ended by "ion" |
\B |
The character at any position except of the word boundary |
\BX\B - This pattern specifies any word with "X" character in the middle of the word |
To filter all objects that begin with STR and end with QUIZ, use the following: ^STR\D*QUIZ$
To filter objects that start with SET, use: ^SET
To filter objects that end with ON, use: ON$
If, for example, stored procedures are prefixed with "sp_" use: ^sp_(a|z) to find stored procedures that start with sp_a or sp_z
To filter all objects that contain _os_ in the middle of the name, use: \S+_os_\S+ (or \B_os_\B)
To filter objects that end with the number, use: \d$
Copyright © 2011 ApexSQL LLC. All Rights Reserved.