<HTML ><HEAD ><TITLE >Perl-compatible Regular Expression functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.44"><LINK REL="HOME" TITLE="PHP Manual" HREF="manual.html"><LINK REL="UP" TITLE="Function Reference" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="pdf_add_annotation" HREF="function.pdf-add-annotation.html"><LINK REL="NEXT" TITLE="preg_match" HREF="function.preg-match.html"></HEAD ><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><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="function.pdf-add-annotation.html" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.preg-match.html" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.pcre" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >XL. Perl-compatible Regular Expression functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN22630" ></A ><P > The syntax for patterns used in these functions closely resembles Perl. The expression should be enclosed in the delimiters, a forward slash (/), for example. Any character can be used for delimiter as long as it's not alphanumeric or backslash (\). If the delimiter character has to be used in the expression itself, it needs to be escaped by backslash. </P ><P > The ending delimiter may be followed by various modifiers that affect the matching. See <A HREF="pcre.pattern.modifiers.html" >Pattern Modifiers</A >. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><P ><B >Example 1. Examples of valid patterns</B ></P ><P ></P ><UL ><LI ><P >/<\/\w+>/</P ></LI ><LI ><P >|(\d{3})-\d+|Sm</P ></LI ><LI ><P >/^(?i)php[34]/</P ></LI ></UL ></DIV ></TD ></TR ></TABLE > </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><P ><B >Example 2. Examples of invalid patterns</B ></P ><P ></P ><UL ><LI ><P >/href='(.*)' - missing ending delimiter</P ></LI ><LI ><P >/\w+\s*\w+/J - unknown modifier 'J'</P ></LI ><LI ><P >1-\d3-\d3-\d4| - missing starting delimiter</P ></LI ></UL ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > The Perl-compatible regular expression functions are available in PHP 4 and in PHP 3.0.9 and up. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="function.preg-match.html" >preg_match</A > — Perform a regular expression match</DT ><DT ><A HREF="function.preg-match-all.html" >preg_match_all</A > — Perform a global regular expression match</DT ><DT ><A HREF="function.preg-replace.html" >preg_replace</A > — Perform a regular expression search and replace</DT ><DT ><A HREF="function.preg-split.html" >preg_split</A > — Split string by a regular expression</DT ><DT ><A HREF="function.preg-quote.html" >preg_quote</A > — Quote regular expression characters</DT ><DT ><A HREF="function.preg-grep.html" >preg_grep</A > — Return array entries that match the pattern</DT ><DT ><A HREF="pcre.pattern.modifiers.html" >Pattern Modifiers</A > — describes possible modifiers in regex patterns</DT ><DT ><A HREF="pcre.pattern.syntax.html" >Pattern Syntax</A > — describes PCRE regex syntax</DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.pdf-add-annotation.html" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="manual.html" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.preg-match.html" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >pdf_add_annotation</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >preg_match</TD ></TR ></TABLE ></DIV ></BODY ></HTML >