<?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>Chris Tate-Davies &#187; preg_match</title>
	<atom:link href="http://www.christatedavies.co.uk/tag/preg_match/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christatedavies.co.uk</link>
	<description>An archive of helpful tit bits of information for development, and probably some stuff that is incomplete, wrong or boring...</description>
	<lastBuildDate>Tue, 31 Jan 2012 11:18:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Retrieve email using regex</title>
		<link>http://www.christatedavies.co.uk/2010/06/23/retrieve-email-using-regex/</link>
		<comments>http://www.christatedavies.co.uk/2010/06/23/retrieve-email-using-regex/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 09:45:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[preg_match]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://www.christatedavies.co.uk/?p=90</guid>
		<description><![CDATA[This horrendous regular expression will parse a string and return a valid email address from it. $email = "&#60;'Freddy'&#62; fred@live.com"; preg_match('/[a-z0-9!#$%&#38;'*+/=?^_`{&#124;}~-]+(?:\.[a-z0-9!#$%&#38;'*+/=?^_`{&#124;}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/', $email, $match); echo $match[0]; This will return: fred@live.com Basically, if you pass an array as the third parameter of the preg_match method, it will be filled with the preg_match results, and the first item of the [...]<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://www.christatedavies.co.uk/2010/06/23/retrieve-email-using-regex/' addthis:title='Retrieve email using regex ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>This horrendous regular expression will parse a string and return a valid email address from it.</p>
<pre>$email = "&lt;'Freddy'&gt; fred@live.com";</pre>
<pre>preg_match('/[a-z0-9!#$%&amp;'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&amp;'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/', $email, $match);</pre>
<pre>echo $match[0];</pre>
<p>This will return:</p>
<pre>fred@live.com</pre>
<p>Basically, if you pass an array as the third parameter of the preg_match method, it will be filled with the preg_match results, and the first item of the array will be the matching string. If you use capturing groups, these will also be filled. Read more about preg_match at the PHP site <a href="http://uk3.php.net/manual/en/function.preg-match.php" target="_blank">here</a>.</p>
<p>I am told that this expression will match 99.9% of valid email addresses in the wild.</p>
<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://www.christatedavies.co.uk/2010/06/23/retrieve-email-using-regex/' addthis:title='Retrieve email using regex ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.christatedavies.co.uk/2010/06/23/retrieve-email-using-regex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

