<?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>coders &#187; regular expressions</title>
	<atom:link href="http://www.gehacktes.net/category/programming/regular-expressions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gehacktes.net</link>
	<description>The Limits of My Language Mean the Limits of My World - Ludwig Wittgenstein</description>
	<lastBuildDate>Sat, 31 Jul 2010 12:33:02 +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>remove all comments from your source code</title>
		<link>http://www.gehacktes.net/2009/02/remove-all-comments-from-your-source-code/</link>
		<comments>http://www.gehacktes.net/2009/02/remove-all-comments-from-your-source-code/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 16:22:15 +0000</pubDate>
		<dc:creator>fschaper</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[strip comments]]></category>

		<guid isPermaLink="false">http://www.gehacktes.net/?p=321</guid>
		<description><![CDATA[while browsing the logs from this site I found that a lot of people are looking for a way to strip comments from their respective sources in visual studio. Well here would be the solution for C/C++ sources at least (in visual studio regular expression dialect). So just fire up your CTRL+H, search and replace [...]]]></description>
			<content:encoded><![CDATA[<p>while browsing the logs from this site I found that a lot of people are looking for a way to strip comments from their respective sources in visual studio.</p>
<p>Well here would be the solution for C/C++ sources at least (in visual studio regular expression dialect).</p>
<p><img class="alignnone size-full wp-image-322" title="replace_comments" src="http://www.gehacktes.net/wp-content/uploads/2009/02/replace_comments.jpg" alt="replace_comments" width="354" height="459" /></p>
<p>So just fire up your CTRL+H, search and replace dialog and strip away. Maybe you will find it wise to create a copy of your project beforehand in case I missed something.</p>
<p><img src="file:///C:/Users/fschaper/AppData/Local/Temp/1/moz-screenshot.jpg" alt="" /></p>
<pre>(/\*(\n|.)@\*/)|(//.*$)</pre>
<p>If you are interested in the visual studio specific dialect of regular expressions please have a look at this <a title="visual studio regex reference" href="http://msdn.microsoft.com/en-us/library/2k3te2cs(VS.80).aspx" target="_blank">msdn reference</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gehacktes.net/2009/02/remove-all-comments-from-your-source-code/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>identify that potential dangling else</title>
		<link>http://www.gehacktes.net/2008/11/identify-that-potential-dangling-else/</link>
		<comments>http://www.gehacktes.net/2008/11/identify-that-potential-dangling-else/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 10:28:04 +0000</pubDate>
		<dc:creator>fschaper</dc:creator>
				<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.gehacktes.net/?p=24</guid>
		<description><![CDATA[For the most part I don&#8217;t take part in the religious coding style debate. I do however try to follow the rule of Abelson and Sussman who say that &#8220;Programs must be written for people to read, and only incidentally for machines to execute.&#8221; If you abide by that rule you automatically take a big [...]]]></description>
			<content:encoded><![CDATA[<p>For the most part I don&#8217;t take part in the religious coding style debate.<br />
I do however try to follow the rule of <em>Abelson and Sussman</em> who say that <cite>&#8220;Programs must be written for people to read, and only incidentally for machines to execute.&#8221;</cite><br />
If you abide by that rule you automatically take a big step towards <a title="Defensive Programming" href="http://en.wikipedia.org/wiki/Defensive_programming">defensive programming</a>.</p>
<p>Some of my colleagues take a more aesthetic approach to coding and prefer constructs like:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// bad</span>
<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> condition <span style="color: #008000;">&#41;</span>
    do_something<span style="color: #008080;">;</span>
<span style="color: #0000ff;">else</span>
    do_something_else<span style="color: #008080;">;</span></pre></div></div>

<p>in which I see a  breach in the guidelines of aforementioned defensive programming because it can lead to a problem known as the <a href="http://en.wikipedia.org/wiki/Dangling_else">dangling else</a> (besides other possible mistakes). To find such problematic sections in my code I use the following regular expression inside the visual studio find dialog:<br />
<code><br />
</code></p>
<p><a href="http://www.gehacktes.net/wp-content/uploads/2008/11/find_replace_regex.jpg"><img class="alignnone size-medium wp-image-68" title="find using regular expression" src="http://www.gehacktes.net/wp-content/uploads/2008/11/find_replace_regex-300x286.jpg" alt="" width="300" height="286" /></a></p>
<p>The expression again for copy/paste:</p>
<pre>&lt;if&gt;:b*\([^{]*\n*[^;]*;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.gehacktes.net/2008/11/identify-that-potential-dangling-else/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>delete empty lines in visual studio</title>
		<link>http://www.gehacktes.net/2008/10/delete-empty-lines-in-visual-studio/</link>
		<comments>http://www.gehacktes.net/2008/10/delete-empty-lines-in-visual-studio/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 17:02:52 +0000</pubDate>
		<dc:creator>fschaper</dc:creator>
				<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.gehacktes.net/?p=14</guid>
		<description><![CDATA[programmers write a lot of text. better yet, they write structured text. that&#8217;s where regular expressions become handy. from time to time there are a lot of repetitive tasks, like deleting hundreds of empty lines out of an source file in VisualStudio 2005. To get rid of them all press CTRL+H (the default hotkey) to [...]]]></description>
			<content:encoded><![CDATA[<p>programmers write a lot of text. better yet, they write structured text. that&#8217;s where regular expressions become handy. from time to time there are a lot of repetitive tasks, like deleting hundreds of empty lines out of an source file in VisualStudio 2005.</p>
<p>To get rid of them all press <strong>CTRL+H</strong> (the default hotkey) to fire up the search+replace dialog. In the find options select Use: Regular expressions as the search method.  In the search textfield enter<strong> ^$\n</strong> and leave the replace with text field empty. Select the scope where search+replace should take place in the &#8220;Look in&#8221; drop down box. Now, fire away.</p>
<p><img class="alignnone size-full wp-image-179" title="search_replace" src="http://www.gehacktes.net/wp-content/uploads/2008/10/search_replace.jpg" alt="search_replace" width="354" height="459" /></p>
<p>As a short hint as to what the expression actually means:<br />
^ = match the beginning of an line<br />
$ = match the end of a line, but not the linefeed character<br />
\n = match the linefeed</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gehacktes.net/2008/10/delete-empty-lines-in-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
