<?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>nicomputer&#039;s blog &#187; Regular Expression</title>
	<atom:link href="http://blog.nicomputer.com/articles/programming/regular-expression/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nicomputer.com</link>
	<description>I am (not?) a Robot!</description>
	<lastBuildDate>Tue, 08 Dec 2009 13:53:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Regex Time, Part 3</title>
		<link>http://blog.nicomputer.com/programming/regular-expression/regex-time-part-3/</link>
		<comments>http://blog.nicomputer.com/programming/regular-expression/regex-time-part-3/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 13:53:04 +0000</pubDate>
		<dc:creator>--Nico</dc:creator>
				<category><![CDATA[Regular Expression]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://blog.nicomputer.com/?p=238</guid>
		<description><![CDATA[How to retrieve a six (6) or ten (10) fixed-length digits string? Test Cases This kind of string should match our pattern: a string of six (6) and only six (6) digits a string of ten (10) and only ten (10) digits All other strings should not match our pattern. The Regular Expression Pattern ^\d{6}(?:\d{4})?$ [...]]]></description>
			<content:encoded><![CDATA[<p>How to retrieve a six (6) or ten (10) fixed-length digits string?</p>
<p><span id="more-238"></span></p>
<h2>Test Cases</h2>
<p>This kind of string should match our pattern:</p>
<ul>
<li>a string of six (6) and only six (6) digits</li>
<li>a string of ten (10) and only ten (10) digits</li>
</ul>
<p>All other strings should not match our pattern.</p>
<h2>The Regular Expression Pattern</h2>
<p><code>^\d{6}(?:\d{4})?$</code></p>
<h2>The explanation</h2>
<ol>
<li><code><strong>^</strong></code>: matches the beginning of the string</li>
<li><code><strong>\d{6}</strong></code> matches exactly six digits.</li>
<li><code><strong>(?:\d{4})?</strong></code> this non-capturing (non-capturing because of <strong>?:</strong>) group matches exactly four digits. This group is optional.</li>
<li><code><strong>$</strong></code>: matches the end of the string</li>
</ol>
<p>So, this regular expression could be read as:<br />
Match a string of exactly six (6) digits which could be optionally followed by a string of exactly four (4) digits.<br />
In conclusion, this regex will match a six (6) digits string or a ten (10) digits string (6 required digits + 4 optional digits).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicomputer.com/programming/regular-expression/regex-time-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regex Time, part 2</title>
		<link>http://blog.nicomputer.com/programming/regular-expression/regex-time-part-2/</link>
		<comments>http://blog.nicomputer.com/programming/regular-expression/regex-time-part-2/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 17:37:59 +0000</pubDate>
		<dc:creator>--Nico</dc:creator>
				<category><![CDATA[Regular Expression]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://blog.nicomputer.com/?p=135</guid>
		<description><![CDATA[Today, one of my co-worker asked me to write a Regex. I love Regex, so it was a pleasure for me to answer him. So, my co-worker wanted to know how to retrieve all digits (and only digits: 0 to 9) following a non-digit character and preceding a pipe &#8220;&#124;&#8221; character ? Test Cases This [...]]]></description>
			<content:encoded><![CDATA[<p>Today, one of my co-worker asked me to write a Regex. I love Regex, so it was a pleasure for me to answer him.</p>
<p>So, my co-worker wanted to know how to retrieve all digits (and only digits: 0 to 9) following a non-digit character and preceding a pipe &#8220;|&#8221; character ?</p>
<p><span id="more-135"></span></p>
<h2>Test Cases</h2>
<p>This kind of string should match our pattern:</p>
<ul>
<li>test123|another456|more789| <em>(should match three strings: &#8220;123&#8243;, &#8220;456&#8243; and &#8220;789&#8243;)</em></li>
<li>justone1|</li>
</ul>
<p>All other strings should not match our pattern.</p>
<h2>The Regular Expression Pattern</h2>
<p><code>(?&lt;!\d)(\d+)(?=\|)</code></p>
<h2>The explanation</h2>
<ol>
<li><code><strong>(?&lt;!\d)</strong></code>: <a href="http://www.regular-expressions.info/lookaround.html">negative lookbehind</a> expression tells to the regex engine that the character preceding our matching pattern must not be a digit. Because I&#8217;m using a lookaround which is a &#8220;zero-width assertion&#8221;, this first expression will not be a part of the matching string</li>
<li><code><strong>(\d+)</strong></code> matches one or more digit character. This group is the only capturing group (our matching string) of the regex.</li>
<li><code><strong>(?=|)</strong></code>: <a href="http://www.regular-expressions.info/lookaround.html">positive lookahead</a> expression tells to the regex engine that the character following our matching pattern must not be a pipe &#8220;|&#8221;. Because I&#8217;m using a lookaround which is a &#8220;zero-width assertion&#8221;, this third expression will not be  a part of the matching string</li>
</ol>
<p>So, this regular expression could be read as:<br />
Match a string of one or more digit character which is preceded by any character except a digit and which is followed by a pipe &#8220;|&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicomputer.com/programming/regular-expression/regex-time-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regex Time, part 1</title>
		<link>http://blog.nicomputer.com/programming/regular-expression/regex-time-part-1/</link>
		<comments>http://blog.nicomputer.com/programming/regular-expression/regex-time-part-1/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 14:59:38 +0000</pubDate>
		<dc:creator>--Nico</dc:creator>
				<category><![CDATA[Regular Expression]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://blog.nicomputer.com/?p=113</guid>
		<description><![CDATA[How to retrieve any string (of at least one character) except the one character string «slash» "/" with a regular expression?]]></description>
			<content:encoded><![CDATA[<p>How to retrieve any string (of at least one character) except the one character string &#8220;/&#8221; (slash) with a regular expression?</p>
<p><span id="more-113"></span></p>
<h2>Test Cases </h2>
<p>These strings should not match our pattern:</p>
<ul>
<li>/</li>
<li><em>an empty string</em></li>
</ul>
<p>All other strings should match our pattern.</p>
<h2>The Regular Expression Pattern</h2>
<p><code>^/.+|[^/].+$</code></p>
<h2>The explanation</h2>
<ol>
<li><code><strong>^</strong></code> matches the beginning of the string</li>
<li><code><strong>/.+</strong></code> matches a string beginning by a &#8220;/&#8221; and following by at least one character</li>
<li><code><strong>|</strong></code> OR operator
<li><code><strong>[^/].+</strong></code> matches a string beginning by any character except &#8220;/&#8221; and following by at least one character</li>
<li><code><strong>$</strong></code> matches the end of the string</li>
</ol>
<p>So, this regular expression could be read as:<br />
Match a string beginning by a &#8220;/&#8221; and following by at least one character or match a string beginning by any character except &#8220;/&#8221; and following by at least one character.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicomputer.com/programming/regular-expression/regex-time-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

