<?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>FlexOOP &#187; Regular Expression</title>
	<atom:link href="http://flexoop.com/tag/regular-expression/feed/" rel="self" type="application/rss+xml" />
	<link>http://flexoop.com</link>
	<description>Flex, AIR, ColdFusion, and everything in between</description>
	<lastBuildDate>Tue, 13 Jul 2010 03:56:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Using Regular Expressions to build ColdFusion getters and setters</title>
		<link>http://flexoop.com/2008/11/using-regular-expressions-to-build-coldfusion-getters-and-setters/</link>
		<comments>http://flexoop.com/2008/11/using-regular-expressions-to-build-coldfusion-getters-and-setters/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 03:30:30 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[RegEx]]></category>
		<category><![CDATA[Regular Expression]]></category>

		<guid isPermaLink="false">http://flexfusion.archfamily.com/?p=39</guid>
		<description><![CDATA[I&#8217;m always looking for ways to make my life a little easier when writing code, and to take the monotony out of the equation wherever I can.  I know there is lots of back-and-forth about whether this method should or should not be used in ColdFusion, but I feel that for the minor incovenience of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m always looking for ways to make my life a little easier when writing code, and to take the monotony out of the equation wherever I can.  I know there is lots of back-and-forth about whether this method should or should not be used in ColdFusion, but I feel that for the minor incovenience of running a reg ex, creating getters and setters in my CFCs/Objects just make sense if just for the very fact of encapsulation.  Plus if you need to alter anything that occurs during a &#8220;set&#8221; operation, nothing outside of the object is broken when you make the change within your object.  Anyway, back to business:</p>
<p>This regular expression can be used in Eclipse (my current IDE) and will convert something that looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.firstName <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.lastName <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>into</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getfirstName&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;any&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> variables.firstName <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;setfirstName&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;val&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.firstName <span style="color: #0000FF;">=</span> arguments.<span style="color: #0000FF;">val</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>The search string is:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.<span style="color: #0000FF;">&#40;</span>\w+<span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">=</span>  <span style="color: #0000FF;">&#91;</span>^<span style="color: #0000FF;">&gt;</span></span>]+&gt;(\r\n)(\t)</pre></div></div>

<p>and the replace string is:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;get$1&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span>  <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;any&quot;</span><span style="color: #0000FF;">&gt;</span></span>$2$3$3<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> variables.$<span style="color: #FF0000;">1</span>  <span style="color: #0000FF;">/&gt;</span></span>$2$3<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>$2$2$3<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;set$1&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span>  <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span><span style="color: #0000FF;">&gt;</span></span>$2$3$3<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;val&quot;</span>  <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>$2$3$3<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.$<span style="color: #FF0000;">1</span> <span style="color: #0000FF;">=</span> arguments.<span style="color: #0000FF;">val</span>  <span style="color: #0000FF;">/&gt;</span></span>$2$3<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>$2$2$</pre></div></div>

<p>The search string contains a &#8220;tab&#8221; character at the end.  This is really just so I can format the output of the getters and setters, but feel free to modify them however you wish.</p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2008/11/using-regular-expressions-to-build-coldfusion-getters-and-setters/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Regular Expressions in Flex Builder</title>
		<link>http://flexoop.com/2008/04/regular-expressions-in-flex-builder/</link>
		<comments>http://flexoop.com/2008/04/regular-expressions-in-flex-builder/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 01:54:22 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[RegEx]]></category>
		<category><![CDATA[Regular Expression]]></category>

		<guid isPermaLink="false">http://flexfusion.archfamily.com/?p=12</guid>
		<description><![CDATA[Up until a couple of months ago, I had not really used the regular expression Find/Replace in Eclipse. I&#8217;d read several blog posts about it, but hadn&#8217;t really played around with it much. This all changed after I was, once again, manually replacing some items in Eclipse (setting multiple properties of an object to those [...]]]></description>
			<content:encoded><![CDATA[<p>Up until a couple of months ago, I had not really used the regular expression Find/Replace in Eclipse. I&#8217;d read several blog posts about it, but hadn&#8217;t really played around with it much. This all changed after I was, once again, manually replacing some items in Eclipse (setting multiple properties of an object to those of an item that had been passed in to the function). About halfway through, I figured I would try using regular expressions to automate the task a bit.  From this point on, just about every find/replace I did was using a regular expression.</p>
<p>All of these examples are for ActionScript, by the way, but could easily be converted to be useful in any other programming language:</p>
<p>For example: <b>(Make sure to remove the double quotes from these examples also.</b>)</p>
<p>I prefer curly braces in my functions to be on the same line as the actual function definition rather than on the next line so I wrote this</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">Find: <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\s</span>+<span style="color: #000099; font-weight: bold;">\{</span>&quot;</span>
Replace: <span style="color: #ff0000;">&quot; {&quot;</span></pre></div></div>

<p>This will take something like:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> testing<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span></pre></div></div>

<p>and change it to</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> testing<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span></pre></div></div>

<p>Not a huge deal to most, but my code OCD <img src='http://flexoop.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  and our in-house coding standards like it on the same line. If I don&#8217;t have to manually do this, it certainly makes things easier.</p>
<p>Now this isn&#8217;t that complex and in most other IDE&#8217;s could be handled pretty easily. However, try doing something like this next example without using some kind of regular expression <img src='http://flexoop.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>(This example is pretty long, so make sure to remove the carriage return before the &#8220;return this&#8221; statement when pasting into your Replace field)</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">Find: <span style="color: #ff0000;">&quot;public var (<span style="color: #000099; font-weight: bold;">\w</span>+):( )?(<span style="color: #000099; font-weight: bold;">\w</span>+)( ?= ?[^;]+)?;(([^<span style="color: #000099; font-weight: bold;">\t</span>])+(<span style="color: #000099; font-weight: bold;">\t</span>)(<span style="color: #000099; font-weight: bold;">\t</span>+)?(<span style="color: #000099; font-weight: bold;">\s</span>+)?)&quot;</span>
Replace: <span style="color: #ff0000;">&quot;private var _$1:$3$4;$5$5public function get $1():$3 {$5$7
return this._$1;$5}$5$5 public function set $1( value:$3 ):void {$5$7this._$1 = value;$5}$5$5&quot;</span></pre></div></div>

<p>This example will take something like:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> companyId:uint;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> companyName:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> isLegit:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;</pre></div></div>

<p>Will be converted to multiple accessors (i.e.setters and getters). I won&#8217;t show all 3, but this is what the first one would be converted to:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _companyId:uint;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> companyId<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:uint <span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0066CC;">this</span>._companyId;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> companyId<span style="color: #66cc66;">&#40;</span> value:uint <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">this</span>._companyId = value;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>That has saved me so much coding time.</p>
<p>Anyway, I wish I had started using these earlier as I&#8217;m now setting up a nice little library of scripts that I can run whenever I need to modify my code. I&#8217;m sure someone has set up a site with a library of these things, but these are just a few that I&#8217;ve set up.</p>
<p>And one very important thing to remember with these:</p>
<p><b>Make sure to check the Regular Expressions checkbox in Find/Replace</b> or it will probably never find anything <img src='http://flexoop.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2008/04/regular-expressions-in-flex-builder/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
