<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP Reference Book Blog &#187; regular expressions</title>
	<atom:link href="http://www.phpreferencebook.com/tag/regular-expressions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpreferencebook.com</link>
	<description>PHP Reference: Beginner to Intermediate PHP5</description>
	<lastBuildDate>Thu, 29 Sep 2011 03:50:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Common Regular Expressions</title>
		<link>http://www.phpreferencebook.com/tips/common-regular-expressions/</link>
		<comments>http://www.phpreferencebook.com/tips/common-regular-expressions/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 05:38:13 +0000</pubDate>
		<dc:creator>Mario Lurig</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[preg_match]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://www.phpreferencebook.com/?p=278</guid>
		<description><![CDATA[I&#8217;ve gotten better and more comfortable with regular expressions as time has passed, and sometimes I spend timing wading through google for some common regular expressions I want to put into use, because I&#8217;m sure someone has already created it. Well, this isn&#8217;t always true (or easy to find), so I decided to collect some [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve gotten better and more comfortable with regular expressions as time has passed, and sometimes I spend timing wading through google for some common regular expressions I want to put into use, because I&#8217;m sure someone has already created it. Well, this isn&#8217;t always true (or easy to find), so I decided to collect some common Regular Expressions that may benefit readers. It&#8217;s a good idea to keep two things handy if you want to play with Regular Expressions yourself:</p>
<ul>
<li>A copy of the PHP book with a tab on pages 149 and 150 for common RegEx syntax</li>
<li>A link to <a href="http://regexpal.com/" target="_blank">RegExPal</a>, a color coding <a href="http://www.phpreferencebook.com/tips/regex-color-coding/">Regular Expression tester</a>.</li>
</ul>
<h1>Common Regular Expressions:</h1>
<h2>Date and Time RegEx</h2>
<p><strong>Time format (no seconds): </strong><br />
HH:MM am/pm</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">^<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">|</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#91;</span><span style="color: #208080;">012</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">|</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>\s?<span style="color: #009900;">&#40;</span>am<span style="color: #339933;">|</span>AM<span style="color: #339933;">|</span>pm<span style="color: #339933;">|</span>PM<span style="color: #009900;">&#41;</span>$</pre></div></div>

<p><strong>Date in mm/dd/yyyy format, with an option for m/d/yyyy (exclude zero&#8217;s)</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">^<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>?<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">|</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#91;</span><span style="color: #208080;">012</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span> \<span style="color: #339933;">/.-</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>?<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">|</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">|</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#91;</span><span style="color: #208080;">01</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span> \<span style="color: #339933;">/.-</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">19</span><span style="color: #339933;">|</span><span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span>\d\d$</pre></div></div>

<p><strong>Date in dd/mm/yyyy format, with an option for d/m/yyyy (exclude zero&#8217;s)</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">^<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>?<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">|</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">|</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#91;</span><span style="color: #208080;">01</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span> \<span style="color: #339933;">/.-</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>?<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">|</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#91;</span><span style="color: #208080;">012</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span> \<span style="color: #339933;">/.-</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">19</span><span style="color: #339933;">|</span><span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span>\d\d$</pre></div></div>

<h2>Demographics RegEx</h2>
<p><strong>Age in years &#8211; max 122</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">^<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">|</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">|</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">|</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>$</pre></div></div>

<p><strong>Height in Feet and Inches:</strong><br />
6&#8217;3&#8243;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">^<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #0000ff;">')?\s?([1-9]|1[01])$</span></pre></div></div>

<h2>Contact Information RegEx</h2>
<p><strong>U.S. Phone Number &#8211; parenthesis, periods, dashes, underscore, and spaces are allowed:</strong><br />
(123)456-7890<br />
(123) 456 &#8211; 7890<br />
( 123 )456-7890<br />
1234567890<br />
123.456.7890<br />
123-456-7890<br />
123 456 7890</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">^<span style="color: #009900;">&#91;</span>\<span style="color: #009900;">&#40;</span>\s\<span style="color: #339933;">.</span>_<span style="color: #339933;">-</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>\d<span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span>\<span style="color: #009900;">&#41;</span>\s\<span style="color: #339933;">.</span>_<span style="color: #339933;">-</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>\d<span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span>\s\<span style="color: #339933;">.</span>_<span style="color: #339933;">-</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>\d<span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#125;</span>$</pre></div></div>

<p><strong>U.S. Zip Code &#8211; 5 or 9 digit with dash</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">^\d<span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>\<span style="color: #339933;">-</span><span style="color: #009900;">&#93;</span>\d<span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span>$</pre></div></div>

<p><strong>Email Address &#8211; (use preg_match) credit goes to <a href="http://fightingforalostcause.net/misc/2006/compare-email-regex.php" target="_blank">fightingforalostcause.net</a></strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">/</span>^<span style="color: #009900;">&#91;</span><span style="color: #339933;">-</span>_a<span style="color: #339933;">-</span>z0<span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span>\<span style="color: #0000ff;">'+*$^&amp;%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&amp;%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?&lt;![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?$/iD</span></pre></div></div>

<h2>Currency RegEx</h2>
<p><strong>Currency &#8211; U.S. Dollars and Cents with commas for multiple&#8217;s of 1000 and a period for the decimal:</strong><br />
$12,000.23</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">^\$?<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">.</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #339933;">|</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#40;</span>\<span style="color: #339933;">.</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #339933;">|</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">.</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #339933;">|</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">.</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #009900;">&#41;</span>$</pre></div></div>

<p><strong>Currency &#8211; British Pounds with commas for multiple&#8217;s of 1000 and a period for the decimal:</strong><br />
£12,000.23</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">^\u00A3?<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">.</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #339933;">|</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#40;</span>\<span style="color: #339933;">.</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #339933;">|</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">.</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #339933;">|</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">.</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #009900;">&#41;</span>$</pre></div></div>

<p><strong>Currency &#8211; Euros with periods for multiple&#8217;s of 1000 and a comma for the decimal:</strong><br />
€12.000,23</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">^\u20AC?<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">.</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #339933;">|</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#40;</span>\<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #339933;">|</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #339933;">|</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #009900;">&#41;</span>$</pre></div></div>

<p><strong>Currency &#8211; Euros, French style, with spaces for multiple&#8217;s of 1000 and a comma for the decimal:</strong><br />
€12 000,23</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">^\u20AC?<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span>\s<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #339933;">|</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#40;</span>\<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #339933;">|</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #339933;">|</span><span style="color: #009900;">&#40;</span>\<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>?<span style="color: #009900;">&#41;</span>$</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.phpreferencebook.com/tips/common-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Testing Regular Expressions with Color Highlighting</title>
		<link>http://www.phpreferencebook.com/tips/regex-color-coding/</link>
		<comments>http://www.phpreferencebook.com/tips/regex-color-coding/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 08:01:20 +0000</pubDate>
		<dc:creator>Mario Lurig</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[ereg]]></category>
		<category><![CDATA[eregi]]></category>
		<category><![CDATA[preg_match]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://www.phpreferencebook.com/?p=236</guid>
		<description><![CDATA[Discovered a great website today while working on a complex Regular Expression: RegExPal.com. The site provides color code highlighting for RegEx syntax, including real-time evaluation of test data. If you, for instance, forget to include a closing or opening parenthesis for a group inside the regular expression, the orphaned parenthesis will be highlighted in red [...]]]></description>
			<content:encoded><![CDATA[<p>Discovered a great website today while working on a complex Regular Expression: <a href="http://regexpal.com/">RegExPal.com</a>. The site provides color code highlighting for RegEx syntax, including real-time evaluation of test data. If you, for instance, forget to include a closing or opening parenthesis for a group inside the regular expression, the orphaned parenthesis will be highlighted in red for easy identification of the error. </p>
<p>Here is a quick screenshot of some of the highlighting in action:<br />
<img src="http://www.phpreferencebook.com/wp-content/uploads/2009/04/regexpal.png" alt="RegExPal Screenshot" title="regexpal" width="567" height="181" class="size-full wp-image-237" /></p>
<p>Be advised that this is based on JavaScript regular expressions, which are comparable to the PERL compatible RegEx functions, such as preg_replace() and preg_match(). It&#8217;s a good idea to get familiar with this syntax, as ereg() and eregi() style functions will be removed from PHP6 when it is released, sometime in the future. Make sure to also checkout the <a href="http://www.amazon.com/gp/product/0596520689?ie=UTF8&#038;tag=phrebobl-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0596520689">Regular Expressions Cookbook</a> contributed to by the author of <a href="http://regexpal.com/">RegExPal.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpreferencebook.com/tips/regex-color-coding/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Regular Expression Syntax (RegEx) Sample</title>
		<link>http://www.phpreferencebook.com/samples/regular-expression-syntax/</link>
		<comments>http://www.phpreferencebook.com/samples/regular-expression-syntax/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 05:03:46 +0000</pubDate>
		<dc:creator>Mario Lurig</dc:creator>
				<category><![CDATA[Samples]]></category>
		<category><![CDATA[PCRE]]></category>
		<category><![CDATA[PERL]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://www.phpreferencebook.com/?p=111</guid>
		<description><![CDATA[The handy Regular Expression Syntax from the PHP book (pages 149-150). Check out the free PDF if you don&#8217;t have it already! Regular Expression Syntax ^ – Start of string $ – End of string . – Any single character ( ) – Group of expressions [] – Item range ( e.g. [afg] means a, [...]]]></description>
			<content:encoded><![CDATA[<p>The handy Regular Expression Syntax from the <a href="http://www.phpreferencebook.com">PHP book</a> (pages 149-150). Check out the <a href="http://www.phpreferencebook.com/pdf">free PDF</a> if you don&#8217;t have it already!</p>
<h3>Regular Expression Syntax</h3>
<p>^ – Start of string<br />
$ – End of string<br />
. – Any single character<br />
( ) – Group of expressions<br />
[] – Item range ( e.g. [afg] means a, f, or g )<br />
[^] – Items not in range ( e.g. [^cde] means not c, d, or e )<br />
- (dash) – character range within an item range ( e.g. [a-z] means a through z )<br />
| (pipe) – Logical or ( e.g. (a|b) means a or b )<br />
? – Zero or one of preceding character/item range<br />
* – Zero or more of preceding character/item range<br />
+ – One or more of preceding character/item range<br />
{integer} – Exactly integer of preceding character/item range ( e.g. a{2} )<br />
{integer,} – Integer or more of preceding character/item range ( e.g. a{2,} )<br />
{integer,integer} – From integer to integer (e.g. a{2,4} means 2 to four of a )<br />
\ – Escape character<br />
[:punct:] – Any punctuation<br />
[:space:] – Any space character<br />
[:blank:] – Any space or tab<br />
[:digit:] – Any digit: 0 through 9<br />
[:alpha:] – All letters: a-z and A-Z<br />
[:alnum:] – All digits and letters: 0-9, a-z, and A-Z<br />
[:xdigit:] – Hexadecimal digit<br />
[:print:] – Any printable character<br />
[:upper:] – All uppercase letters: A-Z<br />
[:lower:] – All lowercase letters: a-z</p>
<h3>PERL Compatible (PCRE) only ( preg_*() )</h3>
<p>/ &#8211; delimiter before and after the expression</p>
<h4>Character classes:</h4>
<p>\c – Control character<br />
\s – Whitespace<br />
\S – Not whitespace<br />
\d – Digit (0-9)<br />
\D – Not a digit<br />
\w – Letter, Digit, Underscore [a-zA-Z0-9_]<br />
\W – Not a letter<br />
\x – Hexadecimal digit<br />
\O – Octal digit</p>
<h4>Modifiers:</h4>
<p>i – Case-insensitive<br />
s – Period matches newline<br />
m – ^ and $ match lines<br />
U – Ungreedy matching<br />
e – Evaluate replacement<br />
x – Pattern over several lines</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpreferencebook.com/samples/regular-expression-syntax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RegEx PERL Compatible Character Class \w</title>
		<link>http://www.phpreferencebook.com/corrections/backslash-w/</link>
		<comments>http://www.phpreferencebook.com/corrections/backslash-w/#comments</comments>
		<pubDate>Sat, 31 May 2008 02:11:43 +0000</pubDate>
		<dc:creator>Mario Lurig</dc:creator>
				<category><![CDATA[Corrections]]></category>
		<category><![CDATA[alphanumeric]]></category>
		<category><![CDATA[PCRE]]></category>
		<category><![CDATA[PERL]]></category>
		<category><![CDATA[preg]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://www.phpreferencebook.com/?p=13</guid>
		<description><![CDATA[(pg. 150) Book version: \w &#8211; Letter (a-z, A-Z) Correct version: \w &#8211; Letter, Digit, Underscore [a-zA-Z0-9_] This is similar to the syntax for alphanumeric: [:alnum:]]]></description>
			<content:encoded><![CDATA[<h3>(pg. 150)</h3>
<p>Book version:</p>
<p>\w &#8211; Letter (a-z, A-Z)</p>
<p>Correct version:</p>
<p>\w &#8211; Letter, Digit, Underscore [a-zA-Z0-9_]</p>
<p>This is similar to the syntax for alphanumeric: [:alnum:]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpreferencebook.com/corrections/backslash-w/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

