<?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 West&#039;s Blog</title>
	<atom:link href="http://gotochriswest.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://gotochriswest.com/blog</link>
	<description>Programming, math, and more.</description>
	<lastBuildDate>Mon, 14 May 2012 19:34:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>POW &#8211; Fixing Compilable JavaScript Code</title>
		<link>http://gotochriswest.com/blog/2012/05/14/pow-fixing-compilable-javascript-code/</link>
		<comments>http://gotochriswest.com/blog/2012/05/14/pow-fixing-compilable-javascript-code/#comments</comments>
		<pubDate>Mon, 14 May 2012 19:24:26 +0000</pubDate>
		<dc:creator>Chris West</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JScript]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Problem of the Week]]></category>

		<guid isPermaLink="false">http://gotochriswest.com/blog/?p=1060</guid>
		<description><![CDATA[Many JavaScript/JScript developers use Google Closure Compiler to compile their code. Even though this tool is a great way of minifying JavaScript code, believe it or not, it doesn&#8217;t always work (at least as of May 14, 2012). The following &#8230; <a href="http://gotochriswest.com/blog/2012/05/14/pow-fixing-compilable-javascript-code/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Many JavaScript/JScript developers use <a href="http://closure-compiler.appspot.com/home" title="Closure Compiler Service" target="_blank">Google Closure Compiler</a> to compile their code.  Even though this tool is a great way of minifying JavaScript code, believe it or not, it doesn&#8217;t always work (at least as of May 14, 2012).  The following JavaScript code works fine when you run it without being minified:</p>
<pre class="brush: jscript; title: ; notranslate">
function b() {
  return a--;
}

var a = 1;
alert(b() &lt; !--a);​  // false
</pre>
<p>Unfortunately, the following minified code presents an issue:</p>
<pre class="brush: jscript; title: ; notranslate">
function b(){return a--}var a=1;alert(b()&lt;!--a);
</pre>
<p>Due to the &#8220;<code>&lt;!--</code>&#8221; character sequence being present, the JavaScript code never runs.  In order to fix the issue, it is requested that no characters be taken away.  The functionality of the function should not be changed.  No parentheses or brackets should be added.  In addition, only a max of three bytes can be added.  With the aforementioned criteria in mind, how can you modify the code to make it work after it has been run through the <a href="http://closure-compiler.appspot.com/home" title="Closure Compiler Service" target="_blank">Google Closure Compiler</a>?</p>
<p>The answer to this Problem of the Week will be posted on May 21, 2012.</p>
]]></content:encoded>
			<wfw:commentRss>http://gotochriswest.com/blog/2012/05/14/pow-fixing-compilable-javascript-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>POW Answer &#8211; 0.999999 Repeating Equals One?</title>
		<link>http://gotochriswest.com/blog/2012/05/14/pow-answer-point-nine-repeating-equals-one/</link>
		<comments>http://gotochriswest.com/blog/2012/05/14/pow-answer-point-nine-repeating-equals-one/#comments</comments>
		<pubDate>Mon, 14 May 2012 19:21:29 +0000</pubDate>
		<dc:creator>Chris West</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Problem of the Week]]></category>

		<guid isPermaLink="false">http://gotochriswest.com/blog/?p=1061</guid>
		<description><![CDATA[The following answers the Problem of the Week from May 7, 2012: One of the simplest ways to prove that 0.999999 = 1 is by doing the following: 0.333333 = 1 / 3 3 &#215; (0.333333) = 3 &#215; (1 &#8230; <a href="http://gotochriswest.com/blog/2012/05/14/pow-answer-point-nine-repeating-equals-one/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The following answers the Problem of the Week from <a title="POW – 0.999999 Repeating Equals One?" href="http://gotochriswest.com/blog/2012/05/07/pow-point-nine-repeating-equals-one/">May 7, 2012</a>:</p>
<p>One of the simplest ways to prove that 0.<span style="text-decoration:overline">999999</span> = 1 is by doing the following:</p>
<ul>
<li>0.<span style="text-decoration:overline">333333</span> = 1 / 3</li>
<li>3 &#215; (0.<span style="text-decoration:overline">333333</span>) = 3 &#215; (1 / 3)</li>
<li>0.<span style="text-decoration:overline">999999</span> = 1</li>
</ul>
<p>As shown above, since it is true 0.<span style="text-decoration:overline">333333</span> is the way to represent 1 / 3 in decimal form, it follows mathematically that 0.<span style="text-decoration:overline">999999</span> is an alternative way to represent 1 in decimal form.  A more extensive discussion can be found <a href="http://en.wikipedia.org/w/index.php?title=0.999..." title="0.999... - Wikipedia" target="_blank">here on Wikipedia</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gotochriswest.com/blog/2012/05/14/pow-answer-point-nine-repeating-equals-one/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PostgreSQL &#8211; Select PL/pgSQL Function Definitions</title>
		<link>http://gotochriswest.com/blog/2012/05/09/postgresql-select-pl-pgsql-function-definition/</link>
		<comments>http://gotochriswest.com/blog/2012/05/09/postgresql-select-pl-pgsql-function-definition/#comments</comments>
		<pubDate>Wed, 09 May 2012 20:56:16 +0000</pubDate>
		<dc:creator>Chris West</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://gotochriswest.com/blog/?p=1054</guid>
		<description><![CDATA[Something that I did before, but never documented until now was querying the database for all of the PL/pgSQL function definitions. In PostgreSQL, you can run the following to pull all of them along with the owner, schema, function name, &#8230; <a href="http://gotochriswest.com/blog/2012/05/09/postgresql-select-pl-pgsql-function-definition/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Something that I did before, but never documented until now was querying the database for all of the PL/pgSQL function definitions.  In PostgreSQL, you can run the following to pull all of them along with the owner, schema, function name, and function definition:</p>
<pre class="brush: sql; title: ; notranslate">
SELECT a.rolname AS &quot;owner&quot;,
  n.nspname AS &quot;schema&quot;,
  p.proname AS &quot;name&quot;,
  pg_get_functiondef(p.oid) AS &quot;definition&quot;
FROM pg_language AS l
JOIN pg_proc AS p
ON p.prolang = l.oid
JOIN pg_namespace AS n
ON p.pronamespace = n.oid
JOIN pg_authid AS a
ON a.oid = p.proowner
WHERE l.lanname = 'plpgsql'
ORDER BY &quot;schema&quot; ASC,
  &quot;name&quot; ASC
</pre>
<p>Of course, you can modify the above query so that you can search for whatever you want based on all of the retrieved fields.  If you are still learning about PostgreSQL, I definitely suggest looking through all of the tables, views, and functions in the pg_catalog schema.</p>
]]></content:encoded>
			<wfw:commentRss>http://gotochriswest.com/blog/2012/05/09/postgresql-select-pl-pgsql-function-definition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript &#8211; Semicolons Are Almost Never Needed</title>
		<link>http://gotochriswest.com/blog/2012/05/08/semicolons-are-almost-never-needed-in-javascript/</link>
		<comments>http://gotochriswest.com/blog/2012/05/08/semicolons-are-almost-never-needed-in-javascript/#comments</comments>
		<pubDate>Tue, 08 May 2012 22:20:09 +0000</pubDate>
		<dc:creator>Chris West</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JScript]]></category>

		<guid isPermaLink="false">http://gotochriswest.com/blog/?p=1050</guid>
		<description><![CDATA[Instead of rewriting the article myself, I figured it is better to simply link to it: http://mislav.uniqpath.com/2010/05/semicolons/. After reading this article, do remember that just because it is stated that they are not needed doesn&#8217;t mean that it is bad &#8230; <a href="http://gotochriswest.com/blog/2012/05/08/semicolons-are-almost-never-needed-in-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Instead of rewriting the article myself, I figured it is better to simply link to it:  <a href="http://mislav.uniqpath.com/2010/05/semicolons/" target="_blank">http://mislav.uniqpath.com/2010/05/semicolons/</a>.  After reading this article, do remember that just because it is stated that they are not needed doesn&#8217;t mean that it is bad to include them. <img src='http://gotochriswest.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://gotochriswest.com/blog/2012/05/08/semicolons-are-almost-never-needed-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>POW Answer &#8211; Differences In Languages</title>
		<link>http://gotochriswest.com/blog/2012/05/07/pow-answer-differences-in-language/</link>
		<comments>http://gotochriswest.com/blog/2012/05/07/pow-answer-differences-in-language/#comments</comments>
		<pubDate>Mon, 07 May 2012 04:00:40 +0000</pubDate>
		<dc:creator>Chris West</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Problem of the Week]]></category>

		<guid isPermaLink="false">http://gotochriswest.com/blog/?p=1044</guid>
		<description><![CDATA[This is the answer to the Problem of the Week that was posted on April 30. The desired answer is 0. The reason is because &#8220;11&#8221; in binary is actually equal to 3. Therefore 3 &#8211; 3 = 0. On &#8230; <a href="http://gotochriswest.com/blog/2012/05/07/pow-answer-differences-in-language/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is the answer to the <a href="http://gotochriswest.com/blog/2012/04/30/pow-differences-in-languages/" title="POW – Differences In Languages">Problem of the Week that was posted on April 30</a>.</p>
<p>The desired answer is 0.  The reason is because &#8220;<code>11</code>&#8221; in binary is actually equal to 3.  Therefore 3 &#8211; 3 = 0.  On the other hand, you could use the following table to see how an infinite amount of answers could be given since we don&#8217;t necessarily know what base was used for the first translation:</p>
<table>
<tr>
<th>Base</th>
<th>Value of 11</th>
<th>Answer</th>
</tr>
<tr>
<td>3</td>
<td>4</td>
<td>4 &#8211; 3 = 1</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>5 &#8211; 3 = 2</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
<td>6 &#8211; 3 = 3</td>
</tr>
<tr>
<td>6</td>
<td>7</td>
<td>7 &#8211; 3 = 4</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>8 &#8211; 3 = 5</td>
</tr>
<tr>
<td>8</td>
<td>9</td>
<td>9 &#8211; 3 = 6</td>
</tr>
<tr>
<td>9</td>
<td>10</td>
<td>10 &#8211; 3 = 7</td>
</tr>
<tr>
<td>&#x22EE;</td>
<td>&#x22EE;</td>
<td>&#x22EE;</td>
</tr>
<tr>
<td>X</td>
<td>X + 1</td>
<td>X + 1 &#8211; 3 = X &#8211; 2</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://gotochriswest.com/blog/2012/05/07/pow-answer-differences-in-language/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>POW &#8211; 0.99999 Repeating Equals One?</title>
		<link>http://gotochriswest.com/blog/2012/05/07/pow-point-nine-repeating-equals-one/</link>
		<comments>http://gotochriswest.com/blog/2012/05/07/pow-point-nine-repeating-equals-one/#comments</comments>
		<pubDate>Mon, 07 May 2012 04:00:29 +0000</pubDate>
		<dc:creator>Chris West</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Problem of the Week]]></category>

		<guid isPermaLink="false">http://gotochriswest.com/blog/?p=1041</guid>
		<description><![CDATA[How can you prove or disprove that 1 = 0.999999&#8230;? The answer to this Problem of the Week can be found here.]]></description>
			<content:encoded><![CDATA[<p>How can you prove or disprove that 1 = 0.<span style="text-decoration:overline;">999999</span>&#8230;?</p>
<p>The answer to this Problem of the Week can be found <a href="http://gotochriswest.com/blog/2012/05/14/pow-answer-point-nine-repeating-equals-one/" title="POW Answer – 0.999999 Repeating Equals One?" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gotochriswest.com/blog/2012/05/07/pow-point-nine-repeating-equals-one/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JScript &#8211; Copy Text To Clipboard</title>
		<link>http://gotochriswest.com/blog/2012/05/04/jscript-copy-text-to-clipboard/</link>
		<comments>http://gotochriswest.com/blog/2012/05/04/jscript-copy-text-to-clipboard/#comments</comments>
		<pubDate>Fri, 04 May 2012 04:00:47 +0000</pubDate>
		<dc:creator>Chris West</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[JScript]]></category>

		<guid isPermaLink="false">http://gotochriswest.com/blog/?p=1035</guid>
		<description><![CDATA[If you are writing a JScript and need a way to copy some text to the clipboard, you can use the following definition: Here is an example code block that calls this function: This function relies on the existence of &#8230; <a href="http://gotochriswest.com/blog/2012/05/04/jscript-copy-text-to-clipboard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you are writing a JScript and need a way to copy some text to the clipboard, you can use the following definition:</p>
<pre class="brush: jscript; title: ; notranslate">
// Uses Internet Explorer to copy text to the clipboard.
function copyToClipboard(text)
{
	var objIE;
	try
	{
		objIE = new ActiveXObject(&quot;InternetExplorer.Application&quot;);
		objIE.Navigate(&quot;about:blank&quot;);
		objIE.document.parentWindow.clipboardData.setData(&quot;Text&quot;, text);
	}
	catch(e)
	{
		WScript.echo(&quot;The following error occurred while trying to &quot;
		  + &quot;access the system's clipboard using Internet Explorer:\n&quot;
		 + e.description);
		return false;
	}
	objIE.Quit();
	return true;
}
</pre>
<p>Here is an example code block that calls this function:</p>
<pre class="brush: jscript; title: ; notranslate">
msg = &quot;This message has just been copied to the system's clipboard.&quot;;
copyToClipboard(msg);
WScript.echo(msg);
</pre>
<p>This function relies on the existence of Internet Explorer on the PC.  Of course, this function is only guaranteed to work for stand-alone JS files or WSF files.</p>
]]></content:encoded>
			<wfw:commentRss>http://gotochriswest.com/blog/2012/05/04/jscript-copy-text-to-clipboard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JScript &#8211; Recursively Call A Script</title>
		<link>http://gotochriswest.com/blog/2012/05/03/jscript-recursively-call-a-script/</link>
		<comments>http://gotochriswest.com/blog/2012/05/03/jscript-recursively-call-a-script/#comments</comments>
		<pubDate>Thu, 03 May 2012 04:00:31 +0000</pubDate>
		<dc:creator>Chris West</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[JScript]]></category>

		<guid isPermaLink="false">http://gotochriswest.com/blog/?p=1030</guid>
		<description><![CDATA[Have you ever wondered how you can recursively call a JScript? Here is an example which shows how it can be done: It is important to note that the above example will not pass any variables that were passed to &#8230; <a href="http://gotochriswest.com/blog/2012/05/03/jscript-recursively-call-a-script/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Have you ever wondered how you can recursively call a JScript?  Here is an example which shows how it can be done:</p>
<pre class="brush: jscript; title: ; notranslate">
WshShell = new ActiveXObject(&quot;WScript.Shell&quot;);
switch(WshShell.Popup(&quot;Do you want to run this script again?&quot;, 10, &quot;Run Script Again&quot;, 4 + 32))
{
  case -1:
    WScript.Echo(&quot;I guess you aren't there.  See'ya!!!&quot;);
    break;
  case 6:
    WshShell.run('&quot;' + WScript.ScriptFullName + '&quot;');
    break;
  case 7:
    WScript.Echo(&quot;Take it easy.&quot;);
    break;
}
</pre>
<p>It is important to note that the above example will not pass any variables that were passed to it.  If you want to try this out on your Windows machine, download <a href='http://gotochriswest.com/blog/wp-content/uploads/2012/05/Recursive-Script.js'>Recursive Script</a> to your computer and double-click it.</p>
]]></content:encoded>
			<wfw:commentRss>http://gotochriswest.com/blog/2012/05/03/jscript-recursively-call-a-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript &#8211; String.prototype.times Imitation</title>
		<link>http://gotochriswest.com/blog/2012/05/02/javascript-string-prototype-times-imitation/</link>
		<comments>http://gotochriswest.com/blog/2012/05/02/javascript-string-prototype-times-imitation/#comments</comments>
		<pubDate>Wed, 02 May 2012 13:57:31 +0000</pubDate>
		<dc:creator>Chris West</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://gotochriswest.com/blog/?p=1027</guid>
		<description><![CDATA[One of my favorite things about JavaScript is the ability to use certain functions to do unexpected things. The following shows you the code that could be used to imitate Prototype&#8217;s corresponding function: Basically the above code creates a new &#8230; <a href="http://gotochriswest.com/blog/2012/05/02/javascript-string-prototype-times-imitation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of my favorite things about JavaScript is the ability to use certain functions to do unexpected things.  The following shows you the code that could be used to imitate <a href="http://prototypejs.org/api/string/times" target="_blank">Prototype&#8217;s</a> corresponding function:</p>
<pre class="brush: jscript; title: ; notranslate">
String.prototype.times = function(count) {
  return (new Array(count + 1)).join(this);
};
</pre>
<p>Basically the above code creates a new array has a length of the specified number plus one.  After that, the <code>join()</code> function is called and the string is used as the delimiter to separate each <code>undefined</code> index.  The way the <code>join()</code> function is written, <code>undefined</code> and <code>null</code> will not show up in the resulting string if they were part of the array.</p>
]]></content:encoded>
			<wfw:commentRss>http://gotochriswest.com/blog/2012/05/02/javascript-string-prototype-times-imitation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regular Expression Examples</title>
		<link>http://gotochriswest.com/blog/2012/05/01/regular-expression-examples/</link>
		<comments>http://gotochriswest.com/blog/2012/05/01/regular-expression-examples/#comments</comments>
		<pubDate>Tue, 01 May 2012 20:09:44 +0000</pubDate>
		<dc:creator>Chris West</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://gotochriswest.com/blog/?p=1004</guid>
		<description><![CDATA[One of the things that I love about string manipulation is the existence of regular expressions. For this reason, I have decided to share a few examples that may help those who are learning about regular expressions so that can &#8230; <a href="http://gotochriswest.com/blog/2012/05/01/regular-expression-examples/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the things that I love about string manipulation is the existence of regular expressions. For this reason, I have decided to share a few examples that may help those who are learning about regular expressions so that can understand them a bit better.</p>
<hr />
<h2>JavaScript &#8211; General Variable Name</h2>
<p>In many languages, a variable must start off with a letter and may be followed by letters, numbers, and/or the underscore character.  Knowing this, we could use the following regular expression in JavaScript to match a variable name:</p>
<pre class="brush: jscript; title: ; notranslate">
var expVarIFlag = /^[A-Z]\w*$/i;
</pre>
<p>Basically, the above regular expression will only match a string if it matches the pattern for a variable name. The reason that I only put <code>[A-Z]</code> and not <code>[A-Za-z]</code> is because in JavaScript you can specify an &#8220;i&#8221; flag after the regular expression which indicates that the expression will be case-insensitive. Another thing to note is that I used the <code>\w</code> class which basically represents a word. A word in regular expressions typically means any letter (A to Z regardless of case), any digit (0 to 9), or the underscore character. The reason I used the asterisk instead of the plus sign is because a variable may be just one letter.</p>
<p>NOTE: Although this regular expression may work for other languages, in JavaScript, a variable name can also start off with an underscore or dollar sign.</p>
<hr />
<h2>PostgreSQL &#8211; Date (MM/DD/YYYY)</h2>
<p>Even though using a regular expression shouldn&#8217;t be the way to completely validate a date, you can do so partially with the following in PostgreSQL:</p>
<pre class="brush: sql; title: ; notranslate">
SELECT id, text
FROM answers
WHERE text ~ '^(0\\d|1[012])/([012]\\d|3[01])/\\d{4}$';
</pre>
<p>The above query will pull all of the answers with a text that matches the pattern to see if it looks like a valid date.</p>
<ol>
<li>First it specifies that the first two characters are a 0 followed by another digit or a 1 followed by either a 0, 1, or 2.</li>
<li>Next should come a forward slash.</li>
<li>Next should be either&#8230;</li>
<ol>
<li> 0, 1, or 2 followed by any digit</li>
<li>or 3 followed by a 0 or 1</li>
</ol>
<li>Finally should be another forward slash followed by four digits.</li>
</ol>
<p>One thing to notice is that in order to properly escape the class inside of a string (which is what we have to do here in PostgreSQL), you have to escape the backslash so that it will be interpreted as one backslash in front of the next character thus rendering &#8220;<code>\\w</code>&#8221; as &#8220;<code>\w</code>&#8220;.</p>
<hr />
<h2>PHP &#8211; Hexadecimal Color Code</h2>
<p>In CSS, a color code can be in many different forms. One accepted form is hexadecimal. The hex form can be three characters or six characters long. It can start off with a number sign, but this symbol isn&#8217;t required. Knowing all of this, we could use the following in PHP to validate the hex color:</p>
<pre class="brush: php; title: ; notranslate">
$pattern = '/^#?([0-9A-F]{3}){1,2}$/i';
$validHex = preg_match($pattern, $_GET['hex']);
</pre>
<p>The <code>preg_match()</code> function is used to validate the GET parameter called &#8220;hex&#8221; against our regular expression:</p>
<ol>
<li>First it specifies that the first character may be a number sign (#).</li>
<li>Next I have defined a parenthesized group which matches any three hexadecimal digits.</li>
<li>After that, I am specifying that my parenthesized group pattern may appear once or two times in a row and that no other characters should follow.</li>
<li>Finally, you will notice that I am again using the &#8220;<code>i</code>&#8221; flag to indicate that this is a case-insensitive pattern.</li>
</ol>
<hr />
<h2>Python &#8211; Simple Image File Names</h2>
<p>Let&#8217;s use Python now to check to see if a file name looks like a valid image name:</p>
<pre class="brush: python; title: ; notranslate">
# Import the regular expression library
import re

# Defining the compiled regular expression.
pat = &quot;^[^/\\?%*:|\&quot;&lt;&gt;]+\\.(jpg|png|gif|bmp)$&quot;
reImg = re.compile(pat, re.I)

# Getting the file name from the user
fileName = raw_input(&quot;File name:  &quot;)

# Determine if the file name is an image name
isImage = reImg.match(fileName) is not None
</pre>
<p>The regular expression created does the following:</p>
<ol>
<li>First makes sure that the string starts off with one more characters which are none of the following:  /  \  ?  %  *  :  |  &#8220;  &lt;  &gt;</li>
<li>In the end it checks that a dot is found followed by one of the following extensions which must appear at the end of the string:</li>
<ol>
<li>jpg</li>
<li>png</li>
<li>gif</li>
<li>bmp</li>
</ol>
<li>It is also important to note that by using &#8220;<code>re.I</code>&#8220;, I specified that casing would be ignored.</li>
</ol>
<p>The code should basically prompt the user for a file name and then validate the string entered to determine if it matches the regular expression for an image.  The boolean value indicating whether or not it is an image is stored in the <code>isImage</code> variable.</p>
<hr />
<h2>VBScript &#8211; Format Large Integer With Commas</h2>
<p>The following is how you could use a regular expression to insert commas into a number (integer):</p>
<pre class="brush: vb; title: ; notranslate">
' Setup the RegExp for testing if input is an integer.
Dim re : Set re = new RegExp
re.Pattern = &quot;^(0|-?[1-9]\d*)$&quot;

' Get the input integer from the user.
input = InputBox(&quot;Enter an integer&quot;, &quot;Your Integer&quot;, 123456789)

' If the input is an integer...
If re.Test(input) Then
  ' Modify the pattern to input the commas correctly.
  re.Pattern = &quot;(\d)(?=(\d{3})+$)&quot;
  re.Global = True

  ' Reformat the integer, if given.
  newInput = re.Replace(input, &quot;$1,&quot;)

  ' Display the input formatted with commas.
  MsgBox input &amp; &quot; became &quot; &amp; newInput

' If the input is not an integer, tell the user so.
Else
  MsgBox &quot;The input given wasn't recognized as an integer.&quot;
End If
</pre>
<p>The first regular expression basically tests to make sure that the input is either simply a zero or one or more digits with the first one being non-zero.  In other words, the first pattern makes sure that the input is an integer that doesn&#8217;t start with a zero (unless it is zero).  The second regular expression is what is used to insert the comma(s) in the right place(s).  It finds every instance in which one digit is followed by at least one group of three digits.  By starting the group off with &#8220;<code>?=</code>&#8221; I am ensuring that the matched group will not be skipped on the next pass through.</p>
]]></content:encoded>
			<wfw:commentRss>http://gotochriswest.com/blog/2012/05/01/regular-expression-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

