Quick Start
Tutorial
Tools & Languages
Examples
Reference
Book Reviews
Regex Reference
Introduction
Table of Contents
Quick Reference
Characters
Basic Features
Character Classes
Shorthands
Anchors
Word Boundaries
Quantifiers
Unicode
Capturing Groups & Backreferences
Named Groups & Backreferences
Special Groups
Mode Modifiers
Recursion & Balancing Groups
Replacement Reference
Characters
Matched Text & Backreferences
Context & Case Conversion
Conditionals
More on This Site
Introduction
Regular Expressions Quick Start
Regular Expressions Tutorial
Replacement Strings Tutorial
Applications and Languages
Regular Expressions Examples
Regular Expressions Reference
Replacement Strings Reference
Book Reviews
Printable PDF
About This Site
RSS Feed & Blog
RegexBuddy—Better than a regular expression reference!

Regular Expression Reference: Anchors

FeatureSyntaxDescriptionExampleJGsoft .NET Java Perl PCRE PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE POSIX BRE POSIX ERE GNU BRE GNU ERE Oracle XML XPath
String anchor ^ (caret) Matches at the start of the string the regex pattern is applied to. ^. matches a in abc\ndef YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESnoYES
String anchor $ (dollar) Matches at the end of the string the regex pattern is applied to. .$ matches f in abc\ndef YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESnoYES
String anchor $ (dollar) Matches before the final line break in the string (if any) in addition to matching at the very end of the string. .$ matches f in abc\ndef\n YESYESYESYESYESYESYESYESYESnononoYESnononononononononon/ano
Line anchor ^ (caret) Matches after each line break in addition to matching at the start of the string, thus matching at the start of each line in the string. ^. matches a and d in abc\ndef YESoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionYESYESbasic
extended
grep
egrep
awk
optionoptionoptionoptionoptionoptionn/aoption
Line anchor $ (dollar) Matches before each line break in addition to matching at the end of the string, thus matching at the end of each line in the string. .$ matches c and f in abc\ndef YESoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionYESYESbasic
extended
grep
egrep
awk
optionoptionoptionoptionoptionoptionn/aoption
String anchor \A Matches at the start of the string the regex pattern is applied to. \A\w matches only a in abc YESYESYESYESYESYESYESYESYESnononoYESYESnoECMA
extended
egrep
awk
nonononono10gR2nono
Attempt anchor \A Matches at the start of the match attempt. \A\w matches a, b, and c when iterating over all matches in abc def nonononononononononononononononoYESnonononononono
Attempt anchor \G Matches at the start of the match attempt. \G\w matches a, b, and c when iterating over all matches in abc def YESnonono4.0–7.9noYESYESYESnonononoYESnononononononononono
Match anchor \G Matches at the end of the previous match during the second and following match attempts. Matches at the start of the string during the first match attempt. \G\w matches a, b, and c when iterating over all matches in abc def noYESYESYES8.00YESnononononononononoECMA
extended
egrep
awk
nononononononono
String anchor \z Matches at the end of the string the regex pattern is applied to. \w\z matches f in abc\ndef but fails to match abc\ndef\n YESYESYESYESYESYESYESYESYESnonononoYESnoECMA
extended
egrep
awk
nonononono10gR2nono
String anchor \Z Matches at the end of the string the regex pattern is applied to. \w\Z matches f in abc\ndef but fails to match abc\ndef\n or abc\ndef\n\n nonononononononononononoYESnononoYESnonononononono
String anchor \Z Matches at the end of the string as well as before the final line break in the string (if any). .\Z matches f in abc\ndef and in abc\ndef\n but fails to match abc\ndef\n\n YESYESYESYESYESYESYESYESYESnonononoYESnonononononono10gR2nono
String anchor \Z Matches at the end of the string as well as before all trailing line breaks in the string (if any). .\Z matches f in abc\ndef and in abc\ndef\n and in abc\ndef\n\n nononononononononononononononoECMA
extended
egrep
awk
nononononononono
String anchor \` (backslash backtick) Matches at the start of the string the regex pattern is applied to. \`\w matches only a in abc nononononononononononononononoECMA
extended
egrep
awk
nononononononono
Attempt anchor \` (backslash backtick) Matches at the start of the match attempt. \`\w matches a, b, and c when iterating over all matches in abc def nononononononononononononononononononoYESYESnonono
String anchor \' (backslash quote) Matches at the end of the string the regex pattern is applied to. \w\' matches f in abc\ndef but fails to match abc\ndef\n nononononononononononononononoECMA
extended
egrep
awk
nononoYESYESnonono
FeatureSyntaxDescriptionExampleJGsoft .NET Java Perl PCRE PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE POSIX BRE POSIX ERE GNU BRE GNU ERE Oracle XML XPath