<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/pcre.pattern.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'reference.pcre.pattern.modifiers.php',
    1 => 'Possible modifiers in regex patterns',
    2 => 'Pattern Modifiers',
  ),
  'up' => 
  array (
    0 => 'pcre.pattern.php',
    1 => 'PCRE Patterns',
  ),
  'prev' => 
  array (
    0 => 'regexp.reference.performance.php',
    1 => 'Performance',
  ),
  'next' => 
  array (
    0 => 'reference.pcre.pattern.differences.php',
    1 => 'Differences From Perl',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pcre/pattern.modifiers.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="reference.pcre.pattern.modifiers" class="article">
 <h1 class="title">Pattern Modifiers</h1>

 
  <p class="para">
   The current possible PCRE modifiers are listed below.  The names
   in parentheses refer to internal PCRE names for these modifiers.
   Spaces and newlines are ignored in modifiers, other characters cause error.
  </p>
  <p class="para">
   <blockquote class="blockquote">
    <dl>
     
      <dt><em>i</em> (<code class="literal">PCRE_CASELESS</code>)</dt>
      <dd>
       <span class="simpara">
        If this modifier is set, letters in the pattern match both
        upper and lower case letters.
       </span>
      </dd>
     
     
      <dt><em>m</em> (<code class="literal">PCRE_MULTILINE</code>)</dt>
      <dd>
       <span class="simpara">
        By default, PCRE treats the subject string as consisting of a
        single &quot;line&quot; of characters (even if it actually contains
        several newlines). The &quot;start of line&quot; metacharacter (^)
        matches only at the start of the string, while the &quot;end of
         line&quot; metacharacter ($) matches only at the end of the
        string, or before a terminating newline (unless
        <em>D</em> modifier is set). This is the same as
        Perl.
       </span>
       <span class="simpara">
        When this modifier is set, the &quot;start of line&quot; and &quot;end of
        line&quot; constructs match immediately following or immediately
        before any newline in the subject string, respectively, as
        well as at the very start and end. This is equivalent to
        Perl&#039;s /m modifier. If there are no &quot;\n&quot; characters in a
        subject string, or no occurrences of ^ or $ in a pattern,
        setting this modifier has no effect.
       </span>
      </dd>
     
     
      <dt><em>s</em> (<code class="literal">PCRE_DOTALL</code>)</dt>
      <dd>
       <span class="simpara">
        If this modifier is set, a dot metacharacter in the pattern
        matches all characters, including newlines. Without it,
        newlines are excluded. This modifier is equivalent to Perl&#039;s
        /s modifier.  A negative class such as [^a] always matches a
        newline character, independent of the setting of this
        modifier.
       </span>
      </dd>
     
     
      <dt><em>x</em> (<code class="literal">PCRE_EXTENDED</code>)</dt>
      <dd>
       <span class="simpara">
        If this modifier is set, whitespace data characters in the
        pattern are totally ignored except when escaped or inside a
        character class, and characters between an unescaped #
        outside a character class and the next newline character,
        inclusive, are also ignored. This is equivalent to Perl&#039;s /x
        modifier, and makes it possible to include commentary inside
        complicated patterns. Note, however, that this applies only
        to data characters. Whitespace characters may never appear
        within special character sequences in a pattern, for example
        within the sequence (?( which introduces a conditional
        subpattern.
       </span>
      </dd>
     
     
      <dt><em>A</em> (<code class="literal">PCRE_ANCHORED</code>)</dt>
      <dd>
       <span class="simpara">
        If this modifier is set, the pattern is forced to be
        &quot;anchored&quot;, that is, it is constrained to match only at the
        start of the string which is being searched (the &quot;subject
        string&quot;).  This effect can also be achieved by appropriate
        constructs in the pattern itself, which is the only way to
        do it in Perl.
       </span>
      </dd>
     
     
      <dt><em>D</em> (<code class="literal">PCRE_DOLLAR_ENDONLY</code>)</dt>
      <dd>
       <span class="simpara">
        If this modifier is set, a dollar metacharacter in the pattern
        matches only at the end of the subject string. Without this
        modifier, a dollar also matches immediately before the final
        character if it is a newline (but not before any other
        newlines).  This modifier is ignored if <em>m</em>
        modifier is set. There is no equivalent to this modifier in
        Perl.
       </span>
      </dd>
     
     
      <dt><em>S</em></dt>
      <dd>
       <span class="simpara">
        When a pattern is going to be used several times, it is
        worth spending more time analyzing it in order to speed up
        the time taken for matching. If this modifier is set, then
        this extra analysis is performed. At present, studying a
        pattern is useful only for non-anchored patterns that do not
        have a single fixed starting character.
        As of PHP 7.3.0 this flag has no effect.
       </span>
      </dd>
     
     
      <dt><em>U</em> (<code class="literal">PCRE_UNGREEDY</code>)</dt>
      <dd>
       <span class="simpara">
        This modifier inverts the &quot;greediness&quot; of the quantifiers so
        that they are not greedy by default, but become greedy if
        followed by <code class="literal">?</code>. It is not compatible with Perl. It can also
        be set by a <code class="literal">(?U)</code>
        <a href="regexp.reference.internal-options.php" class="link">modifier setting within
        the pattern</a> or by a question mark behind a quantifier (e.g.
        <code class="literal">.*?</code>).
       </span>
       <blockquote class="note"><p><strong class="note">Note</strong>: 
        <p class="para">
         It is usually not possible to match more than <a href="pcre.configuration.php#ini.pcre.backtrack-limit" class="link">pcre.backtrack_limit</a>
         characters in ungreedy mode.
        </p>
       </p></blockquote>
      </dd>
     
     
      <dt><em>X</em> (<code class="literal">PCRE_EXTRA</code>)</dt>
      <dd>
       <span class="simpara">
        This modifier turns on additional functionality of PCRE that
        is incompatible with Perl. Any backslash in a pattern that
        is followed by a letter that has no special meaning causes
        an error, thus reserving these combinations for future
        expansion. By default, as in Perl, a backslash followed by a
        letter with no special meaning is treated as a literal.
        There are at present no other features controlled by this
        modifier.
       </span>
      </dd>
     
     
      <dt><em>J</em> (<code class="literal">PCRE_INFO_JCHANGED</code>)</dt>
      <dd>
       <span class="simpara">
        The (?J) internal option setting changes the local <code class="literal">PCRE_DUPNAMES</code>
        option. Allow duplicate names for subpatterns.
        As of PHP 7.2.0 <code class="literal">J</code> is supported as modifier as well.
       </span>
      </dd>
     
     
      <dt><em>u</em> (<code class="literal">PCRE_UTF8</code>)</dt>
      <dd>
       <span class="simpara">
        This modifier turns on additional functionality of PCRE that
        is incompatible with Perl. Pattern and subject strings are
        treated as UTF-8. An invalid subject will cause the preg_* function to
        match nothing; an invalid pattern will trigger an error of
        level E_WARNING. Five and six octet UTF-8 sequences are
        regarded as invalid.
       </span>
      </dd>
     
     
      <dt><em>n</em> (<code class="literal">PCRE_NO_AUTO_CAPTURE</code>)</dt>
      <dd>
       <span class="simpara">
        This modifier makes simple <code class="code">(xyz)</code> groups non-capturing.
        Only named groups like <code class="code">(?&lt;name&gt;xyz)</code> are capturing.
        This only affects which groups are capturing, it is still possible to
        use numbered subpattern references, and the matches array will still
        contain numbered results. Available as of PHP 8.2.0.
       </span>
      </dd>
     
     
      <dt><em>r</em> (<code class="literal">PCRE2_EXTRA_CASELESS_RESTRICT</code>)</dt>
      <dd>
       <span class="simpara">
        When <em>u</em> (<code class="literal">PCRE_UTF8</code>) and <em>i</em> (<code class="literal">PCRE_CASELESS</code>)
        are in effect, this modifier prevents matching across ASCII and non-ASCII characters.
       </span>
       <span class="simpara">
        For example, <code class="code">preg_match(&#039;/\x{212A}/iu&#039;, &quot;K&quot;)</code> matches the Kelvin sign <code class="literal">K</code> (U+212A).
        When <em>r</em> is used (<code class="code">preg_match(&#039;/\x{212A}/iur&#039;, &quot;K&quot;)</code>), it does not match.
       </span>
       <span class="simpara">
        Available as of PHP 8.4.0.
       </span>
      </dd>
     
    </dl>
   </blockquote>
  </p>
</div>
<?php manual_footer($setup); ?>