<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-968600174169680148</id><updated>2011-12-28T14:12:55.013-08:00</updated><category term='character class definision'/><category term='posix'/><category term='MySQL'/><category term='ereg'/><category term='eregi'/><category term='ereg_replace'/><category term='Regular Expressions'/><category term='Cheat Sheet'/><title type='text'>PHP Regular Expression Tutorial</title><subtitle type='html'>Regular Expression Tutorial For Beginners With examples</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://php-regex.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://php-regex.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>biovamps</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>8</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-968600174169680148.post-8640143688358953815</id><published>2008-01-20T11:18:00.000-08:00</published><updated>2008-01-20T11:19:59.659-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Regular Expressions'/><category scheme='http://www.blogger.com/atom/ns#' term='Cheat Sheet'/><title type='text'>MySQL Regular Expressions Cheat Sheet</title><content type='html'>&lt;div class="introhead"&gt;&lt;span style="font-weight: bold;"&gt;MySQL Regular Expressions&lt;/span&gt;&lt;br /&gt;&lt;/div&gt; Regular Expressions in MySQL are used within the REGEXP and RLIKE sections of WHERE clauses in the selection of records for display, update or deletion.  They use Henry Spencer's implementation, which is aimed at conformance with POSIX standard 1003.2, extended version.&lt;br /&gt;&lt;br /&gt;&lt;table class="generaltext" border="1"&gt;  &lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Operator Type&lt;/th&gt;&lt;th&gt;Examples&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;  &lt;tr&gt;&lt;td rowspan="5"&gt;Literal Characters&lt;br /&gt;Match a character exactly&lt;/td&gt; &lt;td&gt;a A y 6 % @&lt;/td&gt;&lt;td&gt;Letters, digits and many special&lt;br /&gt;characters match exactly&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;\$ \^ \+ \\ \?&lt;/td&gt;&lt;td&gt;Precede other special characters&lt;br /&gt;with a \ to cancel their regex special meaning&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;\n \t \r&lt;/td&gt;&lt;td&gt;Literal new line, tab, return&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;\cJ \cG&lt;/td&gt;&lt;td&gt;Control codes&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;\xa3&lt;/td&gt;&lt;td&gt;Hex codes for any character&lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;&lt;td rowspan="4"&gt;Anchors and assertions&lt;/td&gt; &lt;td&gt;^&lt;/td&gt;&lt;td&gt;Field starts with&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;$&lt;/td&gt;&lt;td&gt;Field ends with&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;[[:&lt;:]]&lt;/td&gt;&lt;td&gt;Word starts with&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;[[:&gt;:]]&lt;/td&gt;&lt;td&gt;Word ends with&lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;&lt;td rowspan="6"&gt;Character groups&lt;br /&gt;any 1 character from the group&lt;/td&gt; &lt;td&gt;[aAeEiou]&lt;/td&gt;&lt;td&gt;any character listed from [ to ]&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;[^aAeEiou]&lt;/td&gt;&lt;td&gt;any character except aAeEio or u&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;[a-fA-F0-9]&lt;/td&gt;&lt;td&gt;any hex character (0 to 9 or a to f)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;.&lt;/td&gt;&lt;td&gt;any character at all&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;[[:space:]]&lt;/td&gt;&lt;td&gt;any space character (space \n \r or \t)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;[[:alnum:]]&lt;/td&gt;&lt;td&gt;any alphanumeric character (letter or digit)&lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;&lt;td rowspan="7"&gt;Counts&lt;br /&gt;apply to previous element&lt;/td&gt; &lt;td&gt;+&lt;/td&gt;&lt;td&gt;1 or more ("some")&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;*&lt;/td&gt;&lt;td&gt;0 or more ("perhaps some")&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;?&lt;/td&gt;&lt;td&gt;0 or 1 ("perhaps a")&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;{4}&lt;/td&gt;&lt;td&gt;exactly 4&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;{4,}&lt;/td&gt;&lt;td&gt;4 or more&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;{4,8}&lt;/td&gt;&lt;td&gt;between 4 and 8&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td colspan="2"&gt;Add a ? after any count to turn it sparse (match as few as possible) rather than have it default to greedy&lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;&lt;td rowspan="1"&gt;Alternation&lt;/td&gt; &lt;td&gt;|&lt;/td&gt;&lt;td&gt;either, or&lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;&lt;td rowspan="1"&gt;Grouping&lt;/td&gt; &lt;td&gt;( )&lt;/td&gt;&lt;td&gt;group for count and save to variable&lt;/td&gt;&lt;/tr&gt;  &lt;/tbody&gt;&lt;/table&gt; &lt;br /&gt;The above list shows the most commonly used elements of MySQL regular expressions, and is not exhaustive.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/968600174169680148-8640143688358953815?l=php-regex.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://php-regex.blogspot.com/feeds/8640143688358953815/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=968600174169680148&amp;postID=8640143688358953815' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/8640143688358953815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/8640143688358953815'/><link rel='alternate' type='text/html' href='http://php-regex.blogspot.com/2008/01/mysql-regular-expressions-cheat-sheet.html' title='MySQL Regular Expressions Cheat Sheet'/><author><name>biovamps</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-968600174169680148.post-9051632929127050592</id><published>2008-01-20T11:03:00.000-08:00</published><updated>2008-01-20T11:16:50.695-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='character class definision'/><category scheme='http://www.blogger.com/atom/ns#' term='posix'/><title type='text'>POSIX Character Class Definitions</title><content type='html'>&lt;span style="font-weight: bold;"&gt;POSIX Character Class Definitions&lt;br /&gt;&lt;/span&gt;&lt;table summary="" class="norm" border="0" cellpadding="4" cellspacing="4"&gt;&lt;tbody&gt;&lt;tr valign="top"&gt;&lt;td align="center" width="100"&gt;&lt;h4&gt;Value&lt;/h4&gt;&lt;/td&gt; &lt;td&gt;&lt;h4&gt;Meaning&lt;/h4&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td align="center"&gt;[:digit:]&lt;/td&gt; &lt;td&gt;Only the digits 0 to 9&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td align="center"&gt;[:alnum:]&lt;/td&gt; &lt;td&gt;Any alphanumeric character 0 to 9 OR A to Z or a to z.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td align="center"&gt;[:alpha:]&lt;/td&gt; &lt;td&gt;Any alpha character A to Z or a to z.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td align="center"&gt;[:blank:]&lt;/td&gt; &lt;td&gt;Space and TAB characters only.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td align="center"&gt;[:xdigit:]&lt;/td&gt; &lt;td&gt;Hexadecimal notation 0-9, A-F, a-f.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td align="center"&gt;[:punct:]&lt;/td&gt; &lt;td&gt;Punctuation symbols . , " ' ? ! ; : # $ % &amp;amp; ( ) * + - / &lt; &gt; = @ [ ] \ ^ _ { } | ~ &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td align="center"&gt;[:print:]&lt;/td&gt; &lt;td&gt;Any printable character.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td align="center"&gt;[:space:]&lt;/td&gt; &lt;td&gt;Any whitespace characters (space, tab, NL, FF, VT, CR). Many system abbreviate as \s.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td align="center"&gt;[:graph:]&lt;/td&gt; &lt;td&gt;Exclude whitespace (SPACE, TAB). Many system abbreviate as \W.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td align="center"&gt;[:upper:]&lt;/td&gt; &lt;td&gt;Any alpha character A to Z.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td align="center"&gt;[:lower:]&lt;/td&gt; &lt;td&gt;Any alpha character a to z.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td align="center"&gt;[:cntrl:]&lt;/td&gt; &lt;td&gt;Control Characters NL CR LF TAB VT FF NUL SOH STX EXT EOT ENQ ACK SO SI DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC IS1 IS2 IS3 IS4 DEL.&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;These are always used &lt;b&gt;inside square brackets&lt;/b&gt; in the form [[:alnum:]] or combined as [[:digit:]a-d]&lt;/p&gt;&lt;p style="font-weight: bold;"&gt;Example&lt;/p&gt;&lt;p style="font-weight: bold;"&gt;&lt;b&gt;Replace URLs with links&lt;/b&gt;&lt;/p&gt;&lt;div class="example-contents"&gt; &lt;div class="phpcode"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$text &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ereg_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"[[:alpha:]]+://[^&lt;&gt;[:space:]]+[[:alnum:]/]"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                     &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;a href="\"&gt;\\0&lt;/a&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt; &lt;/span&gt; &lt;/code&gt;&lt;/div&gt;     &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/968600174169680148-9051632929127050592?l=php-regex.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://php-regex.blogspot.com/feeds/9051632929127050592/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=968600174169680148&amp;postID=9051632929127050592' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/9051632929127050592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/9051632929127050592'/><link rel='alternate' type='text/html' href='http://php-regex.blogspot.com/2008/01/posix-character-class-definitions.html' title='POSIX Character Class Definitions'/><author><name>biovamps</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-968600174169680148.post-2121079376989255362</id><published>2008-01-20T09:28:00.000-08:00</published><updated>2008-01-20T11:17:07.278-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ereg_replace'/><title type='text'>ereg_replace — Replace regular expression</title><content type='html'>&lt;span style="font-weight: bold;"&gt;ereg_replace — Replace regular expression &lt;/span&gt;&lt;br /&gt;This function scans string  for matches to pattern , then replaces the matched text&lt;br /&gt;with replacement&lt;br /&gt;string ereg_replace  ( string $pattern  , string $replacement  , string $string  )&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;pattern &lt;/span&gt;- A POSIX extended regular expression.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;replacement &lt;/span&gt;- If pattern  contains parenthesized substrings, replacement  may contain substrings&lt;br /&gt;of the form \\digit, which will be replaced by the text matching the digit'th parenthesized&lt;br /&gt;substring; \\0 will produce the entire contents of string. Up to nine substrings may be used.&lt;br /&gt;Parentheses may be nested, in which case they are counted by the opening parenthesis.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;string &lt;/span&gt;-The input string.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Return Values&lt;/span&gt;&lt;br /&gt;The modified string is returned. If no matches are found in string , then it will be returned&lt;br /&gt;unchanged.&lt;br /&gt;&lt;b&gt;Example#1&lt;br /&gt;&lt;/b&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span style="color: rgb(51, 51, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="example-contents"&gt; &lt;div class="phpcode"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;$str= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This is a test"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" is"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" was"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ereg_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"( )is"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"\\1was"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ereg_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"(( )is)"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"\\2was"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;prints "This was a test"    three times:&lt;br /&gt;&lt;b&gt;Example#2&lt;br /&gt;&lt;/b&gt;&lt;span style="color: rgb(51, 51, 153);"&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code class="CodeSample"&gt;  &lt;/code&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;$s = &lt;span style="color: rgb(255, 0, 0);"&gt;"Coding PHP is fun.";&lt;/span&gt;&lt;br /&gt;$pattern =&lt;span style="color: rgb(204, 0, 0);"&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;"(.*)PHP(.*)";&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;$replacement &lt;span style="color: rgb(255, 0, 0);"&gt;= " They say \\1other languages\\2";&lt;/span&gt;&lt;br /&gt;print &lt;span style="color: rgb(0, 0, 153);"&gt;ereg_replace&lt;/span&gt;(&lt;span style="color: rgb(0, 0, 153);"&gt;$pattern&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 153);"&gt;$replacement&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 153);"&gt;$s&lt;/span&gt;);&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;/div&gt;&lt;code class="CodeSample"&gt;&lt;span style="font-weight: bold;"&gt; Output:&lt;/span&gt;&lt;br /&gt;They say Coding other languages is fun.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;"PHP" is replaced with "other languages", and the sentence is changed a little, using \1 and \2 to access the parts within parentheses.&lt;br /&gt;&lt;/code&gt; &lt;p style="font-weight: bold;"&gt;Example&lt;b&gt;#3&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Replace URLs with links&lt;/b&gt;&lt;/p&gt; &lt;div class="example-contents"&gt; &lt;div class="phpcode"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$text &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ereg_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"[[:alpha:]]+://[^&lt;&gt;[:space:]]+[[:alnum:]/]"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                     &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;a href="\"&gt;\\0&lt;/a&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt; &lt;/span&gt; &lt;/code&gt;&lt;/div&gt;     &lt;/div&gt;&lt;br /&gt;&lt;code class="CodeSample"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/968600174169680148-2121079376989255362?l=php-regex.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://php-regex.blogspot.com/feeds/2121079376989255362/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=968600174169680148&amp;postID=2121079376989255362' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/2121079376989255362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/2121079376989255362'/><link rel='alternate' type='text/html' href='http://php-regex.blogspot.com/2008/01/eregreplace-replace-regular-expression.html' title='ereg_replace — Replace regular expression'/><author><name>biovamps</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-968600174169680148.post-2597202135872538066</id><published>2008-01-20T07:59:00.000-08:00</published><updated>2008-01-20T08:45:40.255-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='eregi'/><title type='text'>eregi — Case insensitive regular expression match</title><content type='html'>&lt;span style="font-weight: bold;"&gt;eregi — Case insensitive regular expression match&lt;br /&gt;&lt;/span&gt;    This function is identical to &lt;a href="http://php-regex.blogspot.com/search/label/ereg" class="function"&gt;ereg()&lt;/a&gt; except that it    ignores case distinction when matching alphabetic characters.&lt;br /&gt;   &lt;span class="type"&gt;int&lt;/span&gt; &lt;span class="methodname"&gt;&lt;b&gt;&lt;b&gt;eregi&lt;/b&gt;&lt;/b&gt;&lt;/span&gt;     ( &lt;span class="methodparam"&gt;&lt;span class="type"&gt;string&lt;/span&gt; &lt;tt class="parameter"&gt;$pattern&lt;/tt&gt;&lt;/span&gt;    , &lt;span class="methodparam"&gt;&lt;span class="type"&gt;string&lt;/span&gt; &lt;tt class="parameter"&gt;$string&lt;/tt&gt;&lt;/span&gt;    [, &lt;span class="methodparam"&gt;&lt;span class="type"&gt;array&lt;/span&gt; &lt;tt class="parameter reference"&gt;&amp;amp;$regs&lt;/tt&gt;&lt;/span&gt;   ] )&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;pattern &lt;/span&gt;- Case insensitive regular expression.&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;string &lt;/span&gt;- The input string.&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;regs &lt;/span&gt;- If matches are found for parenthesized substrings of pattern and the function is called&lt;br /&gt;with the third argument regs , the matches will be stored in the elements of the array regs .&lt;br /&gt;$regs[1] will contain the substring which starts at the first left parenthesis; $regs[2] will&lt;br /&gt;contain the substring starting at the second, and so on. $regs[0] will contain a copy of the&lt;br /&gt;complete string matched.&lt;br /&gt;&lt;b&gt;Example#1&lt;br /&gt;&lt;/b&gt;&lt;div class="example-contents"&gt; &lt;div class="phpcode"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;span style="color: rgb(0, 0, 187);"&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'XYZ'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;eregi&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'z'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;  echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"'$string' contains a 'z' or 'Z'!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;     &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/968600174169680148-2597202135872538066?l=php-regex.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://php-regex.blogspot.com/feeds/2597202135872538066/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=968600174169680148&amp;postID=2597202135872538066' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/2597202135872538066'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/2597202135872538066'/><link rel='alternate' type='text/html' href='http://php-regex.blogspot.com/2008/01/eregi-case-insensitive-regular.html' title='eregi — Case insensitive regular expression match'/><author><name>biovamps</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-968600174169680148.post-3923582388168034285</id><published>2008-01-20T07:35:00.000-08:00</published><updated>2008-01-20T07:45:44.891-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ereg'/><title type='text'>ereg — Regular expression match</title><content type='html'>&lt;span style="font-weight: bold;"&gt;ereg — Regular expression match&lt;br /&gt;&lt;/span&gt;    Searches a &lt;i&gt;&lt;tt class="parameter"&gt;string&lt;/tt&gt;&lt;/i&gt;  for matches to the regular    expression given in &lt;i&gt;&lt;tt class="parameter"&gt;pattern&lt;/tt&gt;&lt;/i&gt;  in a case-sensitive    way.&lt;br /&gt;   &lt;span class="type"&gt;&lt;br /&gt;int&lt;/span&gt; &lt;span class="methodname"&gt;&lt;b&gt;&lt;b&gt;ereg&lt;/b&gt;&lt;/b&gt;&lt;/span&gt;     ( &lt;span class="methodparam"&gt;&lt;span class="type"&gt;string&lt;/span&gt; &lt;tt class="parameter"&gt;$pattern&lt;/tt&gt;&lt;/span&gt;    , &lt;span class="methodparam"&gt;&lt;span class="type"&gt;string&lt;/span&gt; &lt;tt class="parameter"&gt;$string&lt;/tt&gt;&lt;/span&gt;    [, &lt;span class="methodparam"&gt;&lt;span class="type"&gt;array&lt;/span&gt; &lt;tt class="parameter reference"&gt;&amp;amp;$regs&lt;/tt&gt;&lt;/span&gt;   ] )&lt;br /&gt;             &lt;span style="font-style: italic;" class="term"&gt;&lt;tt style="color: rgb(255, 0, 0);" class="parameter"&gt;pattern&lt;/tt&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;-&lt;/span&gt;        Case sensitive regular expression.&lt;br /&gt;&lt;span style="font-style: italic;" class="term"&gt;&lt;tt class="parameter"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;string&lt;/span&gt;-&lt;/tt&gt;&lt;/span&gt;        The input string.&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(255, 0, 0);" class="term"&gt;&lt;i style="font-style: italic;"&gt;&lt;tt class="parameter"&gt;regs&lt;/tt&gt;&lt;/i&gt;&lt;span style="font-style: italic;"&gt; &lt;/span&gt;&lt;/span&gt;-If matches are found for parenthesized substrings of        &lt;i&gt;&lt;tt class="parameter"&gt;pattern&lt;/tt&gt;&lt;/i&gt;  and the function is called with the        third argument &lt;i&gt;&lt;tt class="parameter"&gt;regs&lt;/tt&gt;&lt;/i&gt; , the matches will be stored        in the elements of the array &lt;i&gt;&lt;tt class="parameter"&gt;regs&lt;/tt&gt;&lt;/i&gt; .$regs[1] will contain the substring which starts at the first left        parenthesis; $regs[2] will contain the substring starting at the        second, and so on. $regs[0] will contain a copy of the complete string        matched.&lt;br /&gt;&lt;div class="refsect1 returnvalues"&gt;   &lt;h3 class="title"&gt;Return Values&lt;/h3&gt;      &lt;p class="para"&gt;    Returns the length of the matched string if a match for    &lt;i&gt;&lt;tt class="parameter"&gt;pattern&lt;/tt&gt;&lt;/i&gt;  was found in &lt;i&gt;&lt;tt class="parameter"&gt;string&lt;/tt&gt;&lt;/i&gt; ,    or &lt;b&gt;&lt;tt&gt;FALSE&lt;/tt&gt;&lt;/b&gt; if no matches were found or an error occurred.&lt;br /&gt;If the optional parameter &lt;i&gt;&lt;tt class="parameter"&gt;regs&lt;/tt&gt;&lt;/i&gt;  was not passed or    the length of the matched string is 0, this function returns 1.&lt;/p&gt;&lt;p class="para"&gt;&lt;b&gt;Example#1&lt;/b&gt;&lt;br /&gt;The following code snippet takes a date in ISO format (YYYY-MM-DD) and      prints it in DD.MM.YYYY format:&lt;/p&gt;&lt;div class="example-contents"&gt; &lt;div class="phpcode"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ereg &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$date&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$regs&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$regs[3].$regs[2].$regs[1]"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} else {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Invalid date format: $date"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;b&gt;Example#2&lt;/b&gt;&lt;br /&gt;Check if string only contains letters and numbers.&lt;br /&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ereg&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"[^A-Za-z0-9]"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Error: String can only contain letters and numbers!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;exit();&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;b&gt;Example#3&lt;/b&gt;&lt;br /&gt;This is intended to validate fully specified (international) phone numbers without forcing the user to use the full international format and giving them maximum reasonable flexibility including an optional extension number.&lt;br /&gt;Allows numbers plus any of: space():.ext,+-&lt;br /&gt;Example: +44(0)113 249-0442 ext:1234&lt;br /&gt;The code matches any combination of the allowed character set.&lt;br /&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&lt;?&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;php&lt;br /&gt;    $phoneNumber&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"+44(0)113 249-0442 ext:1234"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$regex&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"[0-9 ():.ext,+-]{"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strlen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$phoneNumber&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;).&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"}"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;    if(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ereg&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$regex&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$phoneNumber&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)){&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"ok"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }else {&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"invalid phone number"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    } &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;/div&gt;     &lt;/div&gt;                 &lt;h3 class="title"&gt;&lt;br /&gt;&lt;/h3&gt;&lt;p class="para"&gt;   &lt;/p&gt;  &lt;/div&gt;&lt;br /&gt;      &lt;/div&gt;&lt;dl&gt;&lt;dd&gt;&lt;div style="text-align: left;"&gt;        &lt;/div&gt;&lt;div style="text-align: left;"&gt;       &lt;/div&gt;     &lt;br /&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;span class="term"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/968600174169680148-3923582388168034285?l=php-regex.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://php-regex.blogspot.com/feeds/3923582388168034285/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=968600174169680148&amp;postID=3923582388168034285' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/3923582388168034285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/3923582388168034285'/><link rel='alternate' type='text/html' href='http://php-regex.blogspot.com/2008/01/ereg-regular-expression-match.html' title='ereg — Regular expression match'/><author><name>biovamps</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-968600174169680148.post-3196547526491572242</id><published>2008-01-19T23:36:00.000-08:00</published><updated>2008-01-20T09:17:48.628-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cheat Sheet'/><title type='text'>PHP Regex Cheat Sheet</title><content type='html'>&lt;div class="codebox"&gt; &lt;h3&gt;Special Sequences&lt;/h3&gt; &lt;ul&gt;&lt;li&gt;&lt;span class="codechar"&gt;\w&lt;/span&gt; - Any “word” character (a-z 0-9 _)&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;\W&lt;/span&gt; - Any non “word” character&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;\s&lt;/span&gt; - Whitespace (space, tab CRLF)&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;\S&lt;/span&gt; - Any non whitepsace character&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;\d&lt;/span&gt; - Digits (0-9)&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;\D&lt;/span&gt; - Any non digit character&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;.&lt;/span&gt;  - (Period) – Any character except newline&lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;Meta Characters&lt;/h3&gt; &lt;ul&gt;&lt;li&gt;&lt;span class="codechar"&gt;^&lt;/span&gt; - Start of subject (or line in multiline mode)&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;$&lt;/span&gt; - End of subject (or line in multiline mode)&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;[&lt;/span&gt; - Start character class definition&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;]&lt;/span&gt; - End character class definition&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;|&lt;/span&gt; - Alternates, eg (a|b) matches a or b&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;(&lt;/span&gt; - Start subpattern&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;)&lt;/span&gt; - End subpattern&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;\&lt;/span&gt; - Escape character&lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;Quantifiers&lt;/h3&gt; &lt;ul&gt;&lt;li&gt;&lt;span class="codechar"&gt;n*&lt;/span&gt;    - Zero or more of n&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;n+&lt;/span&gt;    - One or more of n&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;n ?&lt;/span&gt;    - Zero or one occurrences of n&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;{n}&lt;/span&gt;   - n occurrences exactly&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;{n,}&lt;/span&gt;  - At least n occurrences&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;{,m}&lt;/span&gt;  - At most m occurrences&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;{n,m}&lt;/span&gt; - Between n and m occurrences (inclusive)&lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;Pattern Modifiers&lt;/h3&gt; &lt;ul&gt;&lt;li&gt;&lt;span class="codechar"&gt;i&lt;/span&gt; - Case Insensitive &lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;m&lt;/span&gt; - Multiline mode - ^ and $ match start and end of lines&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;s&lt;/span&gt; - Dotall - . class includes newline&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;x&lt;/span&gt; - Extended– comments and whitespace&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;e&lt;/span&gt; - preg_replace only – enables evaluation of replacement as PHP code&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;S&lt;/span&gt; - Extra analysis of pattern&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;U&lt;/span&gt; - Pattern is ungreedy&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;u&lt;/span&gt; - Pattern is treated as UTF-8&lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;Point based assertions&lt;/h3&gt; &lt;ul&gt;&lt;li&gt;&lt;span class="codechar"&gt;\b&lt;/span&gt; - Word boundary&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;\B&lt;/span&gt; - Not a word boundary&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;\A&lt;/span&gt; - Start of subject&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;\Z&lt;/span&gt; - End of subject or newline at end&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;\z&lt;/span&gt; - End of subject&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;\G&lt;/span&gt; - First matching position in subject&lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;Assertions&lt;/h3&gt; &lt;ul&gt;&lt;li&gt;&lt;span class="codechar"&gt;(?=)&lt;/span&gt; - Positive look ahead assertion foo(?=bar) matches foo when followed by bar&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;(?!)&lt;/span&gt; - Negative look ahead assertion foo(?!bar) matches foo when not followed by bar&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;(?&amp;lt;=)&lt;/span&gt; - Positive look behind assertion (?&lt;span class="codechar"&gt;&amp;lt;&lt;/span&gt;=foo)bar matches bar when preceded by foo&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;(?&lt;!--)&lt;/span--&gt; - Negative look behind assertion (?&lt;!--foo)bar matches bar when not preceded by foo&lt;/li--&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;(?&lt;/span&gt;&lt;span class="codechar"&gt;&amp;gt;&lt;/span&gt;&lt;span class="codechar"&gt;)&lt;/span&gt; - Once-only subpatterns (?&lt;span class="codechar"&gt;&amp;gt;&lt;/span&gt;\d+)bar Performance enhancing when bar not present&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;(?(x))&lt;/span&gt; - Conditional subpatterns&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;(?(3)foo|fu)bar&lt;/span&gt; - Matches foo if 3rd subpattern has matched, fu if not&lt;/li&gt;&lt;li&gt;&lt;span class="codechar"&gt;(?#)&lt;/span&gt; - Comment (?# Pattern does x y or z)&lt;/li&gt;&lt;/ul&gt;&lt;a href="http://www.phpguru.org/downloads/PCRE%20Cheat%20Sheet/PHP%20PCRE%20Cheat%20Sheet.pdf"&gt;Download PHP Regex Cheat sheet&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/968600174169680148-3196547526491572242?l=php-regex.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://php-regex.blogspot.com/feeds/3196547526491572242/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=968600174169680148&amp;postID=3196547526491572242' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/3196547526491572242'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/3196547526491572242'/><link rel='alternate' type='text/html' href='http://php-regex.blogspot.com/2008/01/php-regex-cheat-sheet.html' title='PHP Regex Cheat Sheet'/><author><name>biovamps</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-968600174169680148.post-4570096400362023356</id><published>2008-01-18T03:10:00.000-08:00</published><updated>2008-01-18T03:13:41.503-08:00</updated><title type='text'>How To Negate a Character Class</title><content type='html'>&lt;span class="normalfont"&gt;&lt;b&gt;Using the ^ ('carrot') to negate a character class:&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoNormal"&gt;&lt;span class="normalfont"&gt;Metacharacters &lt;span style=""&gt; &lt;/span&gt;[] &lt;span style=""&gt; &lt;/span&gt;denote a "character class". Within a 'character class' you can have what is called a 'range', which I have been using in the examples above. Lets take a look:&lt;/span&gt;&lt;br /&gt;&lt;span class="normalfont"&gt;^[c-f]$&lt;/span&gt;&lt;br /&gt;&lt;span class="normalfont"&gt;This means "the beginning of the line followed by a lowercase letter between c and f (c,d,e, or f), followed by the end of the line."&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span class="normalfont"&gt;The carrot character, ^, can also be used inside a character class to "negate" it. negating a character class basically means "not this". Lets take a look..&lt;/span&gt;&lt;br /&gt;Eg: &lt;span class="normalfont"&gt;^(.*)[^a-z5-9]*$&lt;/span&gt;&lt;br /&gt;&lt;span class="normalfont"&gt;This basically means "the beginning of the line followed by zero or more of any character followed by zero or more of any digit or character that is NOT lowercase or 5-9.".&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/968600174169680148-4570096400362023356?l=php-regex.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://php-regex.blogspot.com/feeds/4570096400362023356/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=968600174169680148&amp;postID=4570096400362023356' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/4570096400362023356'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/4570096400362023356'/><link rel='alternate' type='text/html' href='http://php-regex.blogspot.com/2008/01/how-to-negate-character-class.html' title='How To Negate a Character Class'/><author><name>biovamps</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-968600174169680148.post-2658729263123988372</id><published>2008-01-18T02:17:00.000-08:00</published><updated>2008-01-20T11:10:07.083-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Regular Expressions'/><title type='text'>Introduction to Regular Expressions in PHP</title><content type='html'>&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-weight: bold;"&gt;Introduction to Regular Expressions in PHP&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;Regular expressions were created by an American mathematician named Stephen Kleene.&lt;br /&gt;PHP supports two different types of regular expressions: POSIX-extended and Perl-Compatible Regular Expressions (PCRE). The PCRE functions are more powerful than the POSIX ones, and faster too, so we will concentrate on them.&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;Some Important Terms&lt;/b&gt;&lt;br /&gt;Let Me Start With an example *.txt&lt;b style=""&gt; &lt;/b&gt;[Find all files with extension txt]&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;b style=""&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;Metacharacter&lt;/b&gt;&lt;br /&gt;A metacharacter is a special character that the regex engine will use to apply "rules" for &lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;Eg: &lt;u&gt;*&lt;/u&gt;.txt&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;Literal text&lt;/b&gt;&lt;br /&gt;Literal text is actual "text" that you are using to be matched in your regular expression.&lt;br /&gt;Eg: *&lt;u&gt;.txt&lt;/u&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/p&gt;        &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;Character Class []&lt;/b&gt;&lt;br /&gt;A character class is something that lets you tell the regex engine what characters (literal&lt;br /&gt;text) that you would like to allow at that point in the regular expression&lt;br /&gt;&lt;u&gt;Eg: [Jj]&lt;/u&gt;ohn&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;Anchor&lt;/b&gt;&lt;br /&gt;An anchor is actually a 'metacharacter', but It doesn't actually match text, only the position of text.&lt;br /&gt;Eg: /^[Jj]ohn$/&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/p&gt;            &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;Whitespace&lt;/b&gt; -&lt;br /&gt;Whitespace is actually "literal text", but it is empty space. a string of:&lt;br /&gt;Eg: $str = " "; is comprised of 'whitespace'.&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;br /&gt;&lt;b style=""&gt;Common Metacharacters and Anchors&lt;/b&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;&lt;br /&gt;&lt;/b&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;Caret &lt;span class="normalfont"&gt;symbol (^)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;A caret (^) character at the beginning of a regular expression indicates that it must match the beginning of the string.&lt;br /&gt;Eg: ^z searches for a part that begins with z.&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;span class="normalfont"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span class="normalfont"&gt;&lt;b style=""&gt;Dollar Symbol($)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;A dollar sign ($) is used to match strings that end with the given pattern&lt;br /&gt;Eg: z$ searches for a part that ends with z.&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;span class="normalfont"&gt;&lt;b style=""&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;Dot (.)&lt;/b&gt;&lt;br /&gt;A Dot metacharacter matches any single character except newline (\).&lt;br /&gt;Eg: pattern h.t matches hat, hothit, hut, h7t, etc&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;The vertical pipe ( | )&lt;/b&gt;&lt;br /&gt;The vertical pipe (|) metacharacter is used for alternatives in a regular expression. It behaves much like a logical OR operator and you should use it if you want to construct a pattern that matches more than one set of characters. For instance, the pattern Utah|Idaho|Nevada matches strings that contain "&lt;st1:state st="on"&gt;Utah&lt;/st1:state&gt;" or "&lt;st1:state st="on"&gt;Idaho&lt;/st1:state&gt;" or "&lt;st1:state st="on"&gt;&lt;st1:place st="on"&gt;Nevada&lt;/st1:place&gt;&lt;/st1:state&gt;". Parentheses give us a way to group sequences. For example, (Nant|b)ucket matches "&lt;st1:place st="on"&gt;Nantucket&lt;/st1:place&gt;" or "bucket". Using parentheses to group together characters for alternation is called grouping.&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;Other &lt;st1:place st="on"&gt;Meta&lt;/st1:place&gt; Characters.&lt;/b&gt;&lt;br /&gt;The metacharacters +, *, ?, and {} affect the number of times a pattern should be matched.&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;Plus (+)&lt;/b&gt;&lt;br /&gt;Match one or more of the preceding expression&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt; &lt;/p&gt;&lt;p&gt;The + (plus) matches the previous character 1 or more times, for example, tre+ will find tree and tread but not trough.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-weight: bold;"&gt;Asterisk/&lt;/span&gt; &lt;b style=""&gt;Star(*)&lt;/b&gt;&lt;br /&gt;Match zero or more of the preceding expression&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt; &lt;/p&gt;&lt;p&gt;The * (asterisk or star) matches the preceding character 0 or more times, for example, tre* will find tree and tread and trough.&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;Question Mark(?)&lt;/b&gt;&lt;br /&gt;Match zero or one of the preceding expression&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;The ? (question mark) matches the preceding character 0 or 1 times only, for example, colou?r will find both color and colour.&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/p&gt;        &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;Curly braces {}&lt;/b&gt;&lt;br /&gt;{1} means "match exactly 1 occurrences of the preceding expression", with one&lt;br /&gt;{1,} means "match 1 or more occurrences of the preceding expression",&lt;br /&gt;{1,5} means "match the previous character if it occurs at least 1 times, but no more than 5 times".&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: bold;"&gt;{n}&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Matches the preceding character n times exactly, for example, to find a local phone number we could use [0-9]{3}-[0-9]{4} which would find any number of the form 123-4567.&lt;/p&gt; &lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; The - (dash) in this case, because it is outside the square brackets, is a &lt;b&gt;literal&lt;/b&gt;. Value is enclosed in braces (curly brackets).&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-weight: bold;"&gt;{n,m}&lt;/span&gt;&lt;/p&gt;&lt;p&gt; Matches the preceding character at least n times but not more than m times, for example, 'ba{2,3}b' will find 'baab' and 'baaab' but NOT 'bab' or 'baaaab'. Values are enclosed in braces (curly brackets).&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-bottom: 12pt;"&gt;&lt;b style=""&gt;Note&lt;/b&gt;&lt;br /&gt;Using these metacharacters and a pair of (parentheses) you can create a number of different and complex search patterns. Here are some examples of different search patterns : &lt;/p&gt;  &lt;table class="MsoNormalTable" style="" border="0" cellpadding="0"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0.75pt; width: 75pt;" width="100"&gt;   &lt;p class="MsoNormal"&gt;abc{3}&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;searches for abccc&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;(abc){3}&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;searches for abcabcabc&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;on|off&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;searches for onff or ooff&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;(on)|(off)&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;searches for on or off&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;b style=""&gt;Quick Reference&lt;/b&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="" border="0" cellpadding="0"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0.75pt; width: 75pt;" width="100"&gt;   &lt;p class="MsoNormal"&gt;^z&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;searches for a part that begins with z.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;z$&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;searches for a part that ends with z.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;z+&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;searches for at least one z in a row.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;z?&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;searches for zero or one z.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;(yz)&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;searches for yz grouped together.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;y|z&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;searches for y or z.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;z{3}&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;searches for zzz.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;z{1,}&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;searches for z or zz or zzz and so on...&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;z{1,3}&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;searches for z or zz or zzz only.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal" style="margin-bottom: 12pt;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; Other metacharacter type searches include...&lt;/span&gt; &lt;/p&gt;  &lt;table class="MsoNormalTable" style="" border="0" cellpadding="0"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0.75pt; width: 75pt;" width="100"&gt;   &lt;p class="MsoNormal"&gt;.&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;searches for ANY character or letter.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;[a-z]&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;searches for any lowercase letter.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;[A-Z]&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;searches for any uppercase letter.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;[0-9]&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;searches for any digit 0 to 9.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;\&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;escapes the next character.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;\n&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;new line.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;\t&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 192.75pt;" width="257"&gt;   &lt;p class="MsoNormal"&gt;tab.&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;    &lt;p class="MsoNormal" style="text-align: justify;"&gt;&lt;b style=""&gt;&lt;span style="color:red;"&gt;Note: &lt;/span&gt;&lt;/b&gt;If you want to match a literal metacharacter in a pattern, you have to escape it with a backslash&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/968600174169680148-2658729263123988372?l=php-regex.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://php-regex.blogspot.com/feeds/2658729263123988372/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=968600174169680148&amp;postID=2658729263123988372' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/2658729263123988372'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/968600174169680148/posts/default/2658729263123988372'/><link rel='alternate' type='text/html' href='http://php-regex.blogspot.com/2008/01/introduction-to-regular-expressions-in.html' title='Introduction to Regular Expressions in PHP'/><author><name>biovamps</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry></feed>
