<?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 Expressions</title>
	<atom:link href="http://flexoop.com/category/regular-expressions/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.1</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.$1  <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.$1 <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>Adding space before and after parentheses</title>
		<link>http://flexoop.com/2008/05/adding-space-before-and-after-parentheses/</link>
		<comments>http://flexoop.com/2008/05/adding-space-before-and-after-parentheses/#comments</comments>
		<pubDate>Thu, 22 May 2008 18:22:53 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Errors]]></category>
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://flexfusion.archfamily.com/?p=16</guid>
		<description><![CDATA[I had previously written a regular expression that adds extra space within parentheses, so (test) would become ( test ). However, this gets more complex the more parentheses that are added to the mix. ((test)) and (((test))) require a much more complex regex statement to work correctly (and find the correct ending parenthesis to match [...]]]></description>
			<content:encoded><![CDATA[<p>I had previously written a regular expression that adds extra space within parentheses, so (test) would become ( test ).  However, this gets more complex the more parentheses that are added to the mix.  ((test)) and (((test))) require a much more complex regex statement to work correctly (and find the correct ending parenthesis to match up with the correct starting parenthesis).</p>
<p>I was rethinking how I did this and came up with a new method.  The only difference is that this test will need to be run twice, once for the opening parenthesis and once for the closing parenthesis.  As I usually just do a &#8220;Replace All&#8221;, I figured it wasn&#8217;t that much more difficult than doing it the old way (plus this will work for a much parenthesis nesting as a user puts in).</p>
<p>The Regular Expression is:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">Find: \<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>?<span style="color: #66cc66;">!</span> <span style="color: #66cc66;">|</span>\<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
Replace: <span style="color: #ff0000;">&quot;( &quot;</span></pre></div></div>

<p>remove the double quotes first&#8230;I just wanted to make the space visible.</p>
<p>This regular expression means:<br />
Find an opening parenthesis</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">\<span style="color: #66cc66;">&#40;</span></pre></div></div>

<p>Then check the next character (but do not include/consume it in the &#8220;find&#8221;).  If it is not a space or a closing parenthesis, match the statement</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>?<span style="color: #66cc66;">!</span> <span style="color: #66cc66;">|</span>\<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>This will work on something like:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>test<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>which, after the first run, becomes</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span> test<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Then the second Regular Expression would be:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">Find: <span style="color: #66cc66;">&#40;</span>?<span style="color: #66cc66;">&lt;!</span> <span style="color: #66cc66;">|</span>\<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>\<span style="color: #66cc66;">&#41;</span>
Replace: <span style="color: #ff0000;">&quot; )&quot;</span></pre></div></div>

<p>remove the double quotes first&#8230;I just wanted to make the space visible.</p>
<p>This regular expression means (starting from the right this time):<br />
Find a closing parenthesis</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">\<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Then check the <em>previous</em> character (but don&#8217;t include/consume it in the &#8220;find&#8221;).  If it is not a space or opening parenthesis, match the statement.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>?<span style="color: #66cc66;">&lt;!</span> <span style="color: #66cc66;">|</span>\<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>This will take the previous finished example of:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span> test<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</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: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span> test<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>By adding the extra space to my code, I think it makes everything a little bit easier to read.  This will work for any type of brackets (or any character for that matter).  In the first find statement, you can replace the parenthesis in \) and \( with \[ or \] or whatever you want.  The same goes for the second find statement.  I don&#8217;t know why I didn&#8217;t think of doing it this way before instead of trying to figure out how to code a really long match for the opening and closing parentheses.  It will definitely make my life easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2008/05/adding-space-before-and-after-parentheses/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Regular Expressions are fun!</title>
		<link>http://flexoop.com/2008/04/regular-expressions-are-fun/</link>
		<comments>http://flexoop.com/2008/04/regular-expressions-are-fun/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 18:10:41 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[RegEx]]></category>

		<guid isPermaLink="false">http://flexfusion.archfamily.com/?p=13</guid>
		<description><![CDATA[Whenever I&#8217;m coding I like things just so I&#8217;m pretty sure it&#8217;s a very mild case of OCD as it really does bug me when things are different. Not so much that I get any kind of other disorders from this, but enough that I want to go in and make my changes/fixes to put [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever I&#8217;m coding I like things <em>just</em> so <img src='http://flexoop.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   I&#8217;m pretty sure it&#8217;s a very mild case of <a href="http://en.wikipedia.org/wiki/Obsessive-compulsive_disorder" target="_blank">OCD</a> as it really does bug me when things are different.  Not so much that I get any kind of <em>other</em> disorders from this, but enough that I want to go in and make my changes/fixes to put in the way I like it.  In order to help me through this, I have started writing many regular expressions that will fix the code, and hopefully be quicker than manually editing the pages.</p>
<p>My company has come up with a set of standards that we&#8217;re trying to follow when writing our code, so, if anyone else joins the company and edits/creates new code they can just follow the guidelines we already have set up.  In order to keep track of all of the regular expressions I&#8217;m writing (and so others can use them if they wish), I&#8217;ve created a <a href="http://flexfusion.archfamily.com/regular-expressions/">Regular Expressions page</a> that I&#8217;ll periodically be updating with new regular expressions each time I use them.  I know they&#8217;re useful to me, so I&#8217;m sure that at least one other person will have a use for them too <img src='http://flexoop.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2008/04/regular-expressions-are-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

