<HTML ><HEAD ><TITLE >Pattern Modifiers</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Regular Expression Functions (Perl-Compatible)" HREF="ref.pcre.html"><LINK REL="PREVIOUS" TITLE="Regular Expression Functions (Perl-Compatible)" HREF="ref.pcre.html"><LINK REL="NEXT" TITLE="Pattern Syntax" HREF="pcre.pattern.syntax.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="ref.pcre.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="pcre.pattern.syntax.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="pcre.pattern.modifiers" ></A >Pattern Modifiers</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN80938" ></A >Pattern Modifiers -- Describes possible modifiers in regex patterns</DIV ><DIV CLASS="refsect1" ><A NAME="AEN80941" ></A ><H2 >Description</H2 ><P > The current possible PCRE modifiers are listed below. The names in parentheses refer to internal PCRE names for these modifiers. </P ><P > <A NAME="AEN80945" ></A ><BLOCKQUOTE CLASS="BLOCKQUOTE" ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><SPAN CLASS="emphasis" ><I CLASS="emphasis" >i</I ></SPAN > (PCRE_CASELESS)</DT ><DD ><P > If this modifier is set, letters in the pattern match both upper and lower case letters. </P ></DD ><DT ><SPAN CLASS="emphasis" ><I CLASS="emphasis" >m</I ></SPAN > (PCRE_MULTILINE)</DT ><DD ><P > By default, PCRE treats the subject string as consisting of a single "line" of characters (even if it actually contains several newlines). The "start of line" metacharacter (^) matches only at the start of the string, while the "end of line" metacharacter ($) matches only at the end of the string, or before a terminating newline (unless <SPAN CLASS="emphasis" ><I CLASS="emphasis" >D</I ></SPAN > modifier is set). This is the same as Perl. </P ><P > When this modifier is set, the "start of line" and "end of line" 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's /m modifier. If there are no "\n" characters in a subject string, or no occurrences of ^ or $ in a pattern, setting this modifier has no effect. </P ></DD ><DT ><SPAN CLASS="emphasis" ><I CLASS="emphasis" >s</I ></SPAN > (PCRE_DOTALL)</DT ><DD ><P > 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's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier. </P ></DD ><DT ><SPAN CLASS="emphasis" ><I CLASS="emphasis" >x</I ></SPAN > (PCRE_EXTENDED)</DT ><DD ><P > 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's /x modifier, and makes it possible to include comments 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. </P ></DD ><DT ><SPAN CLASS="emphasis" ><I CLASS="emphasis" >e</I ></SPAN ></DT ><DD ><P > If this modifier is set, <A HREF="function.preg-replace.html" ><B CLASS="function" >preg_replace()</B ></A > does normal substitution of backreferences in the replacement string, evaluates it as PHP code, and uses the result for replacing the search string. </P ><P > Only <A HREF="function.preg-replace.html" ><B CLASS="function" >preg_replace()</B ></A > uses this modifier; it is ignored by other PCRE functions. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > This modifier was not available in PHP3. </P ></BLOCKQUOTE ></DIV ></DD ><DT ><SPAN CLASS="emphasis" ><I CLASS="emphasis" >A</I ></SPAN > (PCRE_ANCHORED)</DT ><DD ><P > If this modifier is set, the pattern is forced to be "anchored", that is, it is constrained to match only at the start of the string which is being searched (the "subject string"). This effect can also be achieved by appropriate constructs in the pattern itself, which is the only way to do it in Perl. </P ></DD ><DT ><SPAN CLASS="emphasis" ><I CLASS="emphasis" >D</I ></SPAN > (PCRE_DOLLAR_ENDONLY)</DT ><DD ><P > 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 <SPAN CLASS="emphasis" ><I CLASS="emphasis" >m</I ></SPAN > modifier is set. There is no equivalent to this modifier in Perl. </P ></DD ><DT ><SPAN CLASS="emphasis" ><I CLASS="emphasis" >S</I ></SPAN ></DT ><DD ><P > 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. </P ></DD ><DT ><SPAN CLASS="emphasis" ><I CLASS="emphasis" >U</I ></SPAN > (PCRE_UNGREEDY)</DT ><DD ><P > This modifier inverts the "greediness" of the quantifiers so that they are not greedy by default, but become greedy if followed by "?". It is not compatible with Perl. It can also be set by a (?U) modifier setting within the pattern. </P ></DD ><DT ><SPAN CLASS="emphasis" ><I CLASS="emphasis" >X</I ></SPAN > (PCRE_EXTRA)</DT ><DD ><P > 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. </P ></DD ><DT ><SPAN CLASS="emphasis" ><I CLASS="emphasis" >u</I ></SPAN > (PCRE_UTF8)</DT ><DD ><P > This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8. This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32. </P ></DD ></DL ></DIV ></BLOCKQUOTE > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="ref.pcre.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="pcre.pattern.syntax.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Regular Expression Functions (Perl-Compatible)</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.pcre.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Pattern Syntax</TD ></TR ></TABLE ></DIV ></BODY ></HTML >