Training
Learning path
Get Started Querying with Transact-SQL - Training
Get Started Querying with Transact-SQL
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Analytics Platform System (PDW)
The following regular expressions can replace characters or digits in the Find what field of the SQL Server Management Studio Find and Replace dialog box.
Here are steps to enable regular expressions in search.
The Expression Builder button next to the Find what field then becomes available. Select this button to display a list of the available regular expressions. When you choose any item from the Expression Builder, it's inserted into the Find what string.
The following table describes some of the regular expressions in the Expression Builder.
Expression | Description |
---|---|
. |
Match any single character (except a line break) |
.* |
Match any character zero or more times |
.+ |
Match any character one or more times |
[abc] |
Match any character in the set abc |
[^abc] |
Match any character not in the set abc |
\d |
Match any numeric character |
(?([^\r\n])\s) |
Match any whitespace character |
\b |
Match at the beginning or end of the word |
^ |
Match at beginning of line |
.$ |
Match any line break |
\w\r?\n |
Match a word character at end of line |
(dog | cat) |
Capture and implicitly number the expression dog | cat |
(?<pet>dog | cat) |
Capture subexpression dog | cat and name it pet |
Some examples of using regular expressions.
You want to find all SELECT statements in your SQL scripts.
SELECT\s+.*\s+FROM
You want to find all stored procedures that start with "usp_" in your SQL scripts.
CREATE\s+PROCEDURE\s+usp_[A-Za-z0-9_]+
You want to identify all single-line comments (starting with --) in your SQL scripts.
--.*
You want to find all the UPDATE statements in your SQL scripts.
UPDATE\s+.*\s+SET
You want to extract table names from CREATE TABLE statements in your SQL scripts.
CREATE\s+TABLE\s+(\w+)
For more examples, visit Regular Expressions in Visual Studio
Training
Learning path
Get Started Querying with Transact-SQL - Training
Get Started Querying with Transact-SQL