<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Regex : Expressões Regulares (compatíveis com o padrão POSIX)</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="Referência das Funções" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="posix_uname" HREF="function.posix-uname.html"><LINK REL="NEXT" TITLE="ereg_replace" HREF="function.ereg-replace.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="reference" 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" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.posix-uname.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.ereg-replace.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.regex" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >CXXVI. Regex : Expressões Regulares (compatíveis com o padrão POSIX)</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN179529" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.intro" >Introdução</A ></H1 ><DIV CLASS="tip" ><BLOCKQUOTE CLASS="tip" ><P ><B >Dica: </B > PHP também suporta expressões regulares compatatíveis com a sintaxe do PERL usando as <A HREF="ref.pcre.html" >Funções PCRE</A >. Essas funções suportam non-greedy matching, assertions, conditional subpatterns, e várias outras características que não são suportadas pelas Expressões Regulares compatíveis com o padrão POSIX. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Atenção</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > Estas expressões regulares não são seguras para dados binários. As <A HREF="ref.pcre.html" >Funções PCRE</A > são. </P ></TD ></TR ></TABLE ></DIV ><P > Expressões regulares são usadas para manipulações complexas de strings no PHP. As funções suportadas pelas expressões regulares são: <P ></P ><UL ><LI ><P ><A HREF="function.ereg.html" ><B CLASS="function" >ereg()</B ></A ></P ></LI ><LI ><P ><A HREF="function.ereg-replace.html" ><B CLASS="function" >ereg_replace()</B ></A ></P ></LI ><LI ><P ><A HREF="function.eregi.html" ><B CLASS="function" >eregi()</B ></A ></P ></LI ><LI ><P ><A HREF="function.eregi-replace.html" ><B CLASS="function" >eregi_replace()</B ></A ></P ></LI ><LI ><P ><A HREF="function.split.html" ><B CLASS="function" >split()</B ></A ></P ></LI ><LI ><P ><A HREF="function.spliti.html" ><B CLASS="function" >spliti()</B ></A ></P ></LI ></UL > </P ><P > Em todas funções coloque a string da expressão regular no primeiro argumento. PHP usa expressões regulares compatíveis com POSIX definidas pelo POSIX 1003.2. Para um descrição completa das expressões regulares no POSIX veja as man pages sobre regex incluídas no diretório regex de sua distribuição PHP. Por estar no formato de manpages você terá que Utilizar o comando <B CLASS="command" >man /usr/local/src/regex/regex.7</B > para ler a documentação. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.requirements" >Dependências</A ></H1 ><P >Nenhuma biblioteca externa é necessária para compilar esta extensão.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.installation" >Instalação</A ></H1 ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Atenção</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > Do not change the TYPE unless you know what you are doing. </P ></TD ></TR ></TABLE ></DIV ><P > To enable regexp support configure PHP <CODE CLASS="option" >--with-regex[=TYPE]</CODE >. TYPE can be one of system, apache, php. The default is to use php. </P ><P >A versão para Windows do <TT CLASS="literal" >PHP</TT > tem suporte embutido para esta extensão. Você não precisa carregar nenhuma extensão adicional para utilizar essas funções.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.configuration" >Configurações em execução</A ></H1 ><P >Esta extensão não define nenhum parâmetro de configuração no <TT CLASS="filename" >php.ini</TT >.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.resources" >Tipos Resource</A ></H1 ><P >Esta extensão não possui nenhum tipo resource.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.constants" >Constantes pré-definidas</A ></H1 ><P >Esta extensão não possui nenhuma constante.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.examples" >Exemplos</A ></H1 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN179584" ></A ><P ><B >Exemplo 1. Exemplos de Expressões Regulares</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">// Retorna true se "abc" existir em qualquer lugar de $string.<br /></font><font color="#0000BB">ereg </font><font color="#007700">(</font><font color="#DD0000">"abc"</font><font color="#007700">, </font><font color="#0000BB">$string</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// Retorna true se "abc" existir no início de $string.<br /></font><font color="#0000BB">ereg </font><font color="#007700">(</font><font color="#DD0000">"^abc"</font><font color="#007700">, </font><font color="#0000BB">$string</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// Retorna true se "abc" existir no final de $string.<br /></font><font color="#0000BB">ereg </font><font color="#007700">(</font><font color="#DD0000">"abc</font><font color="#007700">$</font><font color="#DD0000">"</font><font color="#007700">, </font><font color="#0000BB">$string</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// Retorna true se o navegador do cliente for Netscape 2, 3 ou MSIE 3.<br /></font><font color="#0000BB">eregi </font><font color="#007700">(</font><font color="#DD0000">"(ozilla.[23]|MSIE.3)"</font><font color="#007700">, </font><font color="#0000BB">$HTTP_USER_AGENT</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// Adiciona três palavras separadas por espaço em $regs[1], $regs[2] e $regs[3].<br /></font><font color="#0000BB">ereg </font><font color="#007700">(</font><font color="#DD0000">"([[:alnum:]]+) ([[:alnum:]]+) ([[:alnum:]]+)"</font><font color="#007700">, </font><font color="#0000BB">$string</font><font color="#007700">,</font><font color="#0000BB">$regs</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// Acrescenta a tag <br /> no início de $string.<br /></font><font color="#0000BB">$string </font><font color="#007700">= </font><font color="#0000BB">ereg_replace </font><font color="#007700">(</font><font color="#DD0000">"^"</font><font color="#007700">, </font><font color="#DD0000">"<br />"</font><font color="#007700">, </font><font color="#0000BB">$string</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// Acrescenta a tag <br />; no final de $string.<br /></font><font color="#0000BB">$string </font><font color="#007700">= </font><font color="#0000BB">ereg_replace </font><font color="#007700">(</font><font color="#DD0000">"</font><font color="#007700">$</font><font color="#DD0000">"</font><font color="#007700">, </font><font color="#DD0000">"<br />"</font><font color="#007700">, </font><font color="#0000BB">$string</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// Remove todos caracteres de nova linha (newline) em $string.<br /></font><font color="#0000BB">$string </font><font color="#007700">= </font><font color="#0000BB">ereg_replace </font><font color="#007700">(</font><font color="#DD0000">"\n"</font><font color="#007700">, </font><font color="#DD0000">""</font><font color="#007700">, </font><font color="#0000BB">$string</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="regex.seealso" >Veja também</A ></H1 ><P > Para expressões regulares compatatíveis com o padrão PERL veja <A HREF="ref.pcre.html" >PCRE, Funções</A >. O estilo simples de wildcard do shell pode ser usado com a função <A HREF="function.fnmatch.html" ><B CLASS="function" >fnmatch()</B ></A >. </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Índice</B ></DT ><DT ><A HREF="function.ereg-replace.html" >ereg_replace</A > -- Substituição através de expressões regulares</DT ><DT ><A HREF="function.ereg.html" >ereg</A > -- Casando expressões regulares</DT ><DT ><A HREF="function.eregi-replace.html" >eregi_replace</A > -- Substituição utilizando expressões regulares insensíveis a maiúsculas e minúsculas</DT ><DT ><A HREF="function.eregi.html" >eregi</A > -- Casando expressões regulares insensíveis a maiúsculas e minúsculas</DT ><DT ><A HREF="function.split.html" >split</A > -- Separa strings em matrizes(array) utilizando expressões regulares</DT ><DT ><A HREF="function.spliti.html" >spliti</A > -- Separa strings em matrizes(array) utilizando expressões regulares insensíveis a maiúsculas e minúsculas </DT ><DT ><A HREF="function.sql-regcase.html" >sql_regcase</A > -- Cria expressões regulares insensíveis a maiúsculas e minúsculas. </DT ></DL ></DIV ></DIV ></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="function.posix-uname.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.ereg-replace.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >posix_uname</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >ereg_replace</TD ></TR ></TABLE ></DIV ></BODY ></HTML >