<p> 正则表达式在PHP中被用来处理复杂的文字串。支持正则表达式的函数有: <blockquote><p> <code>ereg()<br />ereg replace()<br />eregi replace()<br />split() </code></p></blockquote><p> 这些函数都将正则表达式作为他们的第一个参数。PHP使用POSIX扩展规则表达式(使用POSIX 1003.2)。要找到所有的关于POSIX扩展规则表达式的描述,请查看包括在PHP发行版本之内的regex man页面。 </p><p> Example 2-4. Regular expression examples </p><p> <code>ereg("abc",$string); </code></p><blockquote><p> <code>/* Returns true if "abc"<br />is found anywhere in $string. */<br />ereg("^abc",$string);<br />/* Returns true if "abc"<br />is found at the beginning of $string. */<br />ereg("abc$",$string);<br />/* Returns true if "abc"<br />is found at the end of $string. */<br />eregi("(ozilla.[23]|MSIE.3)",$HTTP_USER_AGENT);<br />/* Returns true if client browser<br />is Netscape 2, 3 or MSIE 3. */<br />ereg("([[:alnum:]]+) ([[:alnum:]]+) ([[:alnum:]]+ )",<br />$string,$regs);<br />/* Places three space separated words<br />into $regs[1], $regs[2] and $regs[3]. */<br />ereg_replace("^","<BR>",$string);<br />/* Put a <BR> tag at the beginning of $string. */<br />ereg_replace("$","<BR>",$string);<br />/* Put a <BR> tag at the end of $string. */<br />ereg_replace("\n","",$string);<br />/* Get rid of any carriage return<br />characters in $string. */</code></p></blockquote></p>