<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/reference.pcre.pattern.syntax.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'regexp.reference.anchors.php',
    1 => 'Anchors',
    2 => 'Anchors',
  ),
  'up' => 
  array (
    0 => 'reference.pcre.pattern.syntax.php',
    1 => 'PCRE regex syntax',
  ),
  'prev' => 
  array (
    0 => 'regexp.reference.unicode.php',
    1 => 'Unicode character properties',
  ),
  'next' => 
  array (
    0 => 'regexp.reference.dot.php',
    1 => 'Dot',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pcre/pattern.syntax.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="regexp.reference.anchors" class="section">
  <h2 class="title">Anchors</h2>
  <p class="para">
   Outside a character class, in the default matching mode, the
   circumflex character (<code class="literal">^</code>) is an assertion which
   is true only if the current matching point is at the start of
   the subject string. Inside a character class, circumflex (<code class="literal">^</code>)
   has an entirely different meaning (see below).
  </p>
  <p class="para">
   Circumflex (<code class="literal">^</code>) need not be the first character
   of the pattern if a number of alternatives are involved, but it
   should be the first thing in each alternative in which it appears
   if the pattern is ever to match that branch. If all possible
   alternatives start with a circumflex (<code class="literal">^</code>), that is,
   if the pattern is constrained to match only at the start of the subject,
   it is said to be an &quot;anchored&quot; pattern. (There are also other
   constructs that can cause a pattern to be anchored.)
  </p>
  <p class="para">
   A dollar character (<code class="literal">$</code>) is an assertion which is
   <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> only if the current matching point is at the end of the subject
   string, or immediately before a newline character that is the last
   character in the string (by default). Dollar (<code class="literal">$</code>)
   need not be the last character of the pattern if a number of
   alternatives are involved, but it should be the last item in any branch
   in which it appears. Dollar has no special meaning in a
   character class.
  </p>
  <p class="para">
   The meaning of dollar can be changed so that it matches only
   at the very end of the string, by setting the
   <a href="reference.pcre.pattern.modifiers.php" class="link">PCRE_DOLLAR_ENDONLY</a>
   option at compile or matching time. This does not affect the \Z assertion.
  </p>
  <p class="para">
   The meanings of the circumflex and dollar characters are
   changed if the
   <a href="reference.pcre.pattern.modifiers.php" class="link">PCRE_MULTILINE</a> option
   is set. When this is the case, they match immediately after and
   immediately before an internal &quot;\n&quot; character, respectively, in addition
   to matching at the start and end of the subject string. For example, the
   pattern /^abc$/ matches the subject string &quot;def\nabc&quot; in multiline mode,
   but not otherwise. Consequently, patterns that are anchored in single
   line mode because all branches start with &quot;^&quot; are not anchored in
   multiline mode. The
   <a href="reference.pcre.pattern.modifiers.php" class="link">PCRE_DOLLAR_ENDONLY</a>
   option is ignored if
   <a href="reference.pcre.pattern.modifiers.php" class="link">PCRE_MULTILINE</a> is
   set.
  </p>
  <p class="para">
   Note that the sequences \A, \Z, and \z can be used to match
   the start and end of the subject in both modes, and if all
   branches of a pattern start with \A is it always anchored,
   whether <a href="reference.pcre.pattern.modifiers.php" class="link">PCRE_MULTILINE</a>
   is set or not.
  </p>
 </div><?php manual_footer($setup); ?>