Learn more about Toad for SQL Server
at Quest.com

Find solutions and downloads at the
Toad for SQL Server Support Portal

< To bookmark a page, right-click the Page Title and select Add to Favorites / Bookmark This Page

Toad for SQL Server 5.7

You are here: Edit SQL > Find and Replace > Supported Regular Expressions

Supported Regular Expressions

Toad supports the following regular expressions.

Characters

Character Matches
(normal characters) Characters match themselves, except for the following: . $ ^ { [ ( | ) * + ? \
\t A tab (\u0009)
\r A carriage return (\u000D).
\v A vertical tab (\u000B).
\f A form feed (\u000C).
\n A new line (\u000A).
\e An escape (\u001B).
\040 An ASCII character as octal (three digits). It represents a space.
\x20 An ASCII character using hexadecimal representation (two digits).
\u0020 A Unicode character using hexadecimal representation (four digits).
\

The character immediately following it, when that character is not an escaped character. For example, \* represents a literal ‘*’ rather than the repeat operator.

Character Classes

Character Matches Example
. Any single characters except for \n. When this class is used within a character class, the . is equivalent to a period character.

Expression: d.g

Matches: dog, dig, and dug

[ ] Any character within the brackets.

Expression: d[oi]g

Matches: dog and dig

[^ ] Any character that is not in the specified set of characters.

Expression: d[^u]g

Matches: dog and dig but not dug

[ - ]

Any character within the specified range. [0-9a-fA-F] matches a single hexadecimal digit, without case sensitivity.

Note: The - character is considered a literal character if it used as the first or last character within the brackets, or if it is escaped with a backslash: [xyz-], [-xyz], or [x\-yz].

Expression: do[a-z]

Matches: doe, dog, don, and dot

\w

Any word character (A - Z and a - z), digits, and underscores.

Text: dogs dig underneath fences

Expression: d\w\w

Matches: dog in "dogs", dig, and der in "underneath"

\W Any non-word character.

Text: 8pm @ Main Street

Expression: \W

Matches: @

\s Any whitespace character.

Text: dogs dig underneath fences

Expression: d\w\w\s

Matches: "dig " (the match includes the space after dig)

\S Any non-whitespace character.

Text: dogs dig underneath fences 

Expression: d\w\w\S

Matches: dogs and dern in "underneath"

\d Any digit.

Text: DEC-2009

Expression: \d\d\d\d

Matches: 2009

\D Any non-digit.

Text: DEC-2009

Expression: \D\D\D

Matches: DEC

Quantifiers

Character Specifies Example
* Zero or more matches of the preceding character.

Expression: we*

Matches: w, we, weee, and so on

+ One or more matches of the preceding character. Expression: du+de

Matches: dude, duuude, but not dde

? Zero or one matches of the preceding character.

Expression: colou?r 

Matches: color and colour

{n} The exact number of matches for the preceding character.

Text: be careful around bees

Expression: be{2}

Matches: bee in "bees"

{n,m} The preceding character must match at least "n" times but no more than "m" times.

Expression: so{2,3}n

Matches: soon and sooon, but not son or soooon

Anchors

Character Match Occurs Example
^ At the beginning of the document or new line.

Text: dogs dig

underneath fences

Expression: ^\w+

Matches:dogs and underneath

$ At the end of the string, the end of the line, or before \n.

Text: dogs dig
underneath fences

Expression: \w+$

Matches: dig and fences

\A At the beginning of the document. Does not match after a line break.

Text: dogs dig
underneath fences

Expression: \A\w+

Matches: dogs but not underneath

\z At the end of the document.

Text: dogs dig
underneath fences

Expression: \w+\z

Matches: fences but not dig

\b At the beginning or end of a word, or between a word character (\w) and a non-word character (\W).

Text: tons of buttons

Expression: \bton

Matches: ton in "tons"

\B Anywhere except at the beginning or end of a word.

Text: tons of buttons 

Expression: \Bton

Matches: ton in "buttons"

Grouping Constructs

Character Description Example
( ) Matches substring when used in a find and replace

Text: dogs dig underneath fences

Expression: dogs (\w+) underneath (\w+)

Capture $1: dig

Capture $2: fences

Note: See $1 in the Substitutions table below.

(?= )

A zero-width positive look-ahead assertion.

Expression: ^(?=.{32}$)(\d+)

Matches: numbers at the beginning of any line which is exactly 32 characters long

Capture $1: the number

(?! ) A zero-width negative look-ahead assertion.

Expression: ^(?!.{32}$)(\d+)

Matches: numbers at the beginning of any line which is not 32 characters long

Capture $1: the number

(?<= ) A zero-width positive look-behind assertion.

Expression: (?<=19)99

Matches: instances of 99 that follow 19

(?<! ) A zero-width negative look-behind assertion.

Expression: (?<!19)99

Matches: instances of 99 that do not follow 19

(?# ) A comment within a regular expression. The comment ends after the first closing parenthesis.

"(d|l)og(?# I like dogs and log messages)"

is equivalent to

"(d|l)og" and both expressions match "dog" or "log"

| Defines alternates that match the left or right values.

Expression: gr(a|e)y

Matches: gray and grey

Substitutions

Character Description Example
$1

Is replaced by the string matched by the first grouping construct. $2 is replaced by the second string, and so on.

Text: dogs dig underneath fences

Expression: (\w+) dig

Substitution: I like $1

Produces: I like dogs

$& Is replaced by the entire matched substring.

Text: dogs dig underneath fences 

Expression: (\w+) dig

Substitution: I like $1, because $&

Produces: I like dogs, because dogs dig

$$ Produces a dollar sign ($).

Text:12.38

Expression: (\d\d\.\d\d)

Substitution: Tax: $$$1

Produces: Tax: $12.38

  

Related Topics

Find and Replace In Files