<?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>Kalen Gibbons &#187; regular expression</title>
	<atom:link href="http://www.kalengibbons.com/blog/index.php/tag/regular-expression/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kalengibbons.com/blog</link>
	<description>The Dead Tree Blog</description>
	<lastBuildDate>Mon, 24 Oct 2011 20:43:10 +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>Simple string replacement with RegExp and Apex</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/10/simple-string-replacement-with-regexp-and-apex/</link>
		<comments>http://www.kalengibbons.com/blog/index.php/2008/10/simple-string-replacement-with-regexp-and-apex/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 05:56:09 +0000</pubDate>
		<dc:creator>Kalen Gibbons</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Apex]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[SalesForce]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=45</guid>
		<description><![CDATA[Sometimes it&#8217;s hard to figure out even simple thing in a proprietary language like Apex. So here is a simple solution to a common problem. How do I replace string elements using Regular Expressions in Apex? //create expression as Pattern Pattern dollarPattern = Pattern.compile(&#8216;[,$]&#8216;); //replace all occurrences in a string dollarPattern.matcher(&#8216;$1,250.25&#8242;).replaceAll(&#8221;); You need to use [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes it&#8217;s hard to figure out even simple thing in a proprietary language like Apex.  So here is a simple solution to a common problem.</p>
<p><strong>How do I replace string elements using Regular Expressions in Apex?</strong></p>
<div class="code">
<p><span class="asComment">//create expression as Pattern</span><br />
    Pattern dollarPattern = Pattern.compile(<span class="asString">&#8216;[,$]&#8216;</span>);</p>
<p><span class="asComment">//replace all occurrences in a string</span><br />
    dollarPattern.matcher(<span class="asString">&#8216;$1,250.25&#8242;</span>).replaceAll(<span class="asString">&#8221;</span>);</p>
</div>
<p>You need to use Apex&#8217;s Pattern class to create the regular expression.  Then you can replace all matches in the string using the replaceAll() method.</p>
<p>This example takes a dollar formatted string ($1,250.25) and removes the dollar sign and comma to turn it into a number.  The result would be 1250.25, perfect for database insertion or what have you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kalengibbons.com/blog/index.php/2008/10/simple-string-replacement-with-regexp-and-apex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

