Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 12165

php-manual-en-7.2.11-1.mga7.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Delimiters</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="regexp.introduction.html">Introduction</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="regexp.reference.meta.html">Meta-characters</a></div>
 <div class="up"><a href="reference.pcre.pattern.syntax.html">PCRE regex syntax</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="regexp.reference.delimiters" class="section">
  <h2 class="title">Delimiters</h2>
  <p class="para">
   When using the PCRE functions, it is required that the pattern is enclosed
   by <em class="emphasis">delimiters</em>. A delimiter can be any non-alphanumeric,
   non-backslash, non-whitespace character.
  </p>
  <p class="para">
   Often used delimiters are forward slashes (<em>/</em>), hash
   signs (<em>#</em>) and tildes (<em>~</em>). The
   following are all examples of valid delimited patterns.
   <div class="informalexample">
    <div class="example-contents">
<div class="cdata"><pre>
/foo bar/
#^[^0-9]$#
+php+
%[a-zA-Z0-9_-]%
</pre></div>
    </div>

   </div>
  </p>
  <p class="para">
   It is also possible to use
   bracket style delimiters where the opening and closing brackets are the
   starting and ending delimiter, respectively. <em>()</em>,
   <em>{}</em>, <em>[]</em> and <em>&lt;&gt;</em>
   are all valid bracket style delimiter pairs.
   <div class="informalexample">
    <div class="example-contents">
<div class="cdata"><pre>
(this [is] a (pattern))
{this [is] a (pattern)}
[this [is] a (pattern)]
&lt;this [is] a (pattern)&gt;
</pre></div>
    </div>

   </div>
   Bracket style delimiters do not need to be escaped when they are used as meta
   characters within the pattern, but as with other delimiters they must be
   escaped when they are used as literal characters.
  </p>
  <p class="para">
   If the delimiter needs to be matched inside the pattern it must be
   escaped using a backslash. If the delimiter appears often inside the
   pattern, it is a good idea to choose another delimiter in order to increase
   readability.
   <div class="informalexample">
    <div class="example-contents">
<div class="cdata"><pre>
/http:\/\//
#http://#
</pre></div>
    </div>

   </div>
   The <span class="function"><a href="function.preg-quote.html" class="function">preg_quote()</a></span> function may be used to escape a string
   for injection into a pattern and its optional second parameter may be used
   to specify the delimiter to be escaped.
  </p>
  <p class="para">
   You may add <a href="reference.pcre.pattern.modifiers.html" class="link">pattern
   modifiers</a> after the ending delimiter. The following is an example
   of case-insensitive matching:
   <div class="informalexample">
    <div class="example-contents">
<div class="cdata"><pre>
#[a-z]#i
</pre></div>
    </div>

   </div>
  </p>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="regexp.introduction.html">Introduction</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="regexp.reference.meta.html">Meta-characters</a></div>
 <div class="up"><a href="reference.pcre.pattern.syntax.html">PCRE regex syntax</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>