Quick Start
Tutorial
Search & Replace
Tools & Languages
Examples
Reference
Regex Reference
Introduction
Table of Contents
Quick Reference
Characters
Basic Features
Character Classes
Shorthands
Anchors
Word Boundaries
Quantifiers
Capturing Groups & Backreferences
Named Groups & Backreferences
Special Groups
Unicode Characters and Properties
Unicode Versions
Unicode Categories
Unicode Scripts
Unicode Blocks
Unicode Binary Properties
Unicode Property Sets
Unicode Boundaries
Mode Modifiers
Recursion & Balancing Groups
Backtracking Control Verbs
Replacement Reference
Characters
Matched Text & Backreferences
Case Conversion
Context
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 Python JavaScript VBScript XRegExp .NET Java ICU RE2 Perl PCRE PCRE2 PHP Delphi R Ruby std::regex Boost Tcl POSIX GNU 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 YESYESnononoYESYESYESnoYESYESYESYESYESYESnonononononoYESn/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 YESoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionYESYESbasic
extended
grep
egrep
awk
optionoptionoptionoptionn/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 YESoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionoptionYESYESbasic
extended
grep
egrep
awk
optionoptionoptionoptionn/aoption
String anchor \A Matches at the start of the string the regex pattern is applied to. \A\w matches only a in abc YESYESnononoYESYESYESdefaultYESYESYESYESYESYESYESnoECMA
extended
egrep
awk
nononoYESnono
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 nonononononononononononononononononoYESnonononono
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 YESnonononononononono4.5–7.9noYESYESYESYESnononononononono
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 nononononoYESYESYESnoYES8.00YESnononononoECMA
extended
egrep
awk
nononononono
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 YESnonononoYESYESYESdefaultYESYESYESYESYESYESYESnoECMA
extended
egrep
awk
nononoYESnono
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 noYESnonononononononononononononononoYESnonononono
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 YESnonononoYESYESYESnoYESYESYESYESYESYESYESnononononoYESnono
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 nononononononononononononononononoECMA
extended
egrep
awk
nononononono
String anchor \` (backslash backtick) Matches at the start of the string the regex pattern is applied to. \`\w matches only a in abc nononononononononononononononononoECMA
extended
egrep
awk
nononononono
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 nonononononononononononononononononononoYESnonono
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 nononononononononononononononononoECMA
extended
egrep
awk
nonoYESnonono
FeatureSyntaxDescriptionExampleJGsoft Python JavaScript VBScript XRegExp .NET Java ICU RE2 Perl PCRE PCRE2 PHP Delphi R Ruby std::regex Boost Tcl POSIX GNU Oracle XML XPath

Ad-Free Access and Printable PDF Download

If you find the content on this website helpful they you may want a copy you can read offline or even print, or browse the site as often as you want without ads. You can purchase your own copy of the Regular-Expressions.info printable PDF download. As a bonus, you'll get a lifetime of advertisement-free access to this site!