<?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"
	>

<channel>
	<title>Regex Guru</title>
	<atom:link href="http://www.regexguru.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.regexguru.com</link>
	<description>Irregular updates on the wonderful world of regular expressions by Jan Goyvaerts, developer of premier regular expression software and web sites</description>
	<pubDate>Mon, 03 Oct 2011 01:25:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>Expressões Regulares Cookbook</title>
		<link>http://www.regexguru.com/2011/10/expressoes-regulares-cookbook/</link>
		<comments>http://www.regexguru.com/2011/10/expressoes-regulares-cookbook/#comments</comments>
		<pubDate>Mon, 03 Oct 2011 01:25:51 +0000</pubDate>
		<dc:creator>Jan Goyvaerts</dc:creator>
		
		<category><![CDATA[Regex Cookbook]]></category>

		<guid isPermaLink="false">http://www.regexguru.com/?p=135</guid>
		<description><![CDATA[Regular Expressions Cookbook is now available in Brazilian Portuguese.]]></description>
			<content:encoded><![CDATA[<p>I received my author copy of “Expressões Regulares Cookbook” last week. This is the Brazilian Portuguese translation of Regular Expressions Cookbook. You can <a href="http://www.novatec.com.br/livros/regexpcookbook/">buy Expressões Regulares Cookbook from the publisher Novatec</a> or any bookstore that sells Brazilian Portuguese language books. Ask for ISBN 978-85-7522-279-9.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.regexguru.com/2011/10/expressoes-regulares-cookbook/feed/</wfw:commentRss>
		</item>
		<item>
		<title>한 권으로 끝내는 정규표현식</title>
		<link>http://www.regexguru.com/2011/09/%ed%95%9c-%ea%b6%8c%ec%9c%bc%eb%a1%9c-%eb%81%9d%eb%82%b4%eb%8a%94-%ec%a0%95%ea%b7%9c%ed%91%9c%ed%98%84%ec%8b%9d/</link>
		<comments>http://www.regexguru.com/2011/09/%ed%95%9c-%ea%b6%8c%ec%9c%bc%eb%a1%9c-%eb%81%9d%eb%82%b4%eb%8a%94-%ec%a0%95%ea%b7%9c%ed%91%9c%ed%98%84%ec%8b%9d/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 01:25:50 +0000</pubDate>
		<dc:creator>Jan Goyvaerts</dc:creator>
		
		<category><![CDATA[Regex Cookbook]]></category>

		<guid isPermaLink="false">http://www.regexguru.com/?p=133</guid>
		<description><![CDATA[Regular Expressions Cookbook is now available in Korean.]]></description>
			<content:encoded><![CDATA[<p>I received my author copy of “한 권으로 끝내는 정규표현식” last month. This is the Korean translation of Regular Expressions Cookbook. You can <a href="http://www.hanb.co.kr/book/look.html?isbn=978-89-7914-774-2">buy 한 권으로 끝내는 정규표현식 from the publisher Hanbit Media, Inc.</a> or any bookstore that sells Korean language books. Ask for ISBN 978-89-7914-774-2.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.regexguru.com/2011/09/%ed%95%9c-%ea%b6%8c%ec%9c%bc%eb%a1%9c-%eb%81%9d%eb%82%b4%eb%8a%94-%ec%a0%95%ea%b7%9c%ed%91%9c%ed%98%84%ec%8b%9d/feed/</wfw:commentRss>
		</item>
		<item>
		<title>#1 O&#8217;Reilly eBook for 2010</title>
		<link>http://www.regexguru.com/2010/12/1-oreilly-ebook-for-2010/</link>
		<comments>http://www.regexguru.com/2010/12/1-oreilly-ebook-for-2010/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 03:21:55 +0000</pubDate>
		<dc:creator>Jan Goyvaerts</dc:creator>
		
		<category><![CDATA[Regex Cookbook]]></category>

		<guid isPermaLink="false">http://www.regexguru.com/?p=131</guid>
		<description><![CDATA[Regular Expressions Cookbook is O'Reilly's top seller in ebook format in 2010, leading the trend that digital publishing is poised to overtake print.]]></description>
			<content:encoded><![CDATA[<p>The year-end issue of O&#8217;Reilly&#8217;s author newsletter discussed the trends O&#8217;Reilly has been seeing the past few years, and their predictions for 2011.  The key trend is that digital is now more than ever poised to take over print:</p>
<blockquote><p>Our digitally distributed products have grown from 18.36% of our publishing mix in 2009 to 28.09% of our mix in 2010. What is more impressive is that our digitally distributed products have produced more than double the revenue that has been lost with the decline of print. I think this is important because some say that digital cannibalizes print products. Our data indicates the contrary, as print is declining much more slowly than digital is growing. I think we may be seeing developers purchasing a print book, and then purchasing the electronic editions to search and copying code from, as the incremental cost for digital is more than reasonable.</p></blockquote>
<p>My own book seems to be leading this trend.  Thanks to everyone who purchased it!</p>
<blockquote><p>And the five bestselling O&#8217;Reilly ebook products for 2010: 1) <a href="http://oreilly.com/catalog/9780596520694/">Regular Expressions Cookbook</a>, 2) <a href="http://oreilly.com/catalog/9780596159788/">jQuery Cookbook</a>, 3) <a href="http://oreilly.com/catalog/9780596158071/">Learning Python</a>, 4) <a href="http://oreilly.com/catalog/9780596806033/">HTML5: Up and Running</a>, and 5) <a href="http://oreilly.com/catalog/9780596806149/">JavaScript Cookbook</a>. I think it&#8217;s interesting that the top five ebooks are code-intensive books. They&#8217;re great products for search and code reuse.</p></blockquote>
<p>It&#8217;s also interesting that none of the top 5 ebooks made the top 5 of print books.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.regexguru.com/2010/12/1-oreilly-ebook-for-2010/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bug in Delphi XE RegularExpressions Unit</title>
		<link>http://www.regexguru.com/2010/09/bug-in-delphi-xe-regularexpressions-unit/</link>
		<comments>http://www.regexguru.com/2010/09/bug-in-delphi-xe-regularexpressions-unit/#comments</comments>
		<pubDate>Wed, 22 Sep 2010 04:16:16 +0000</pubDate>
		<dc:creator>Jan Goyvaerts</dc:creator>
		
		<category><![CDATA[Regex Trouble]]></category>

		<guid isPermaLink="false">http://www.regexguru.com/?p=127</guid>
		<description><![CDATA[A bug in RegularExpressions.pas in Delphi XE may result in fewer matches or blank matches or in an access violation.  This article explains the cause of the bug and how to fix it.]]></description>
			<content:encoded><![CDATA[<p>Using the new RegularExpressions unit in Delphi XE, you can iterate over all the matches that a regex finds in a string like this:</p>
<pre>procedure TForm1.Button1Click(Sender: TObject);
var
  RegEx: TRegEx;
  Match: TMatch;
begin
  RegEx := TRegex.Create('\w+');
  Match := RegEx.Match('One two three four');
  while Match.Success do begin
    Memo1.Lines.Add(Match.Value);
    Match := Match.NextMatch;
  end
end;</pre>
<p>Or you could save yourself two lines of code by using the static <code>TRegEx.Match</code> call:</p>
<pre>procedure TForm1.Button2Click(Sender: TObject);
var
  Match: TMatch;
begin
  Match := TRegEx.Match('One two three four', '\w+');
  while Match.Success do begin
    Memo1.Lines.Add(Match.Value);
    Match := Match.NextMatch;
  end
end;</pre>
<p>Unfortunately, due to a bug in the RegularExpressions unit, the static call doesn&#8217;t work.  Depending on your exact code, you may get fewer matches than you should, or you may get blank matches, or your application may crash with an access violation.</p>
<p>The RegularExpressions unit defines <code>TRegEx</code> and <code>TMatch</code> as records.  That way you don&#8217;t have to explicitly create and destroy them.  Internally, <code>TRegEx</code> uses <code>TPerlRegEx</code> to do the heavy lifting.  <code>TPerlRegEx</code> is a class that needs to be created and destroyed like any other class.  If you look at the <code>TRegEx</code> source code, you&#8217;ll notice that it uses an interface to destroy the <code>TPerlRegEx</code> instance when <code>TRegEx</code> goes out of scope.  Interfaces are reference counted in Delphi, making them usable for automatic memory management.</p>
<p>The bug is that <code>TMatch</code> and <code>TGroupCollection</code> also need the <code>TPerlRegEx</code> instance to do their work.  <code>TRegEx</code> passes its <code>TPerlRegEx</code> instance to <code>TMatch</code> and <code>TGroupCollection</code>, but it does not pass the instance of the interface that is responsible for destroying <code>TPerlRegEx</code>.</p>
<p>This is not a problem in our first code sample.  <code>TRegEx</code> stays in scope until we&#8217;re done with <code>TMatch</code>.  The interface is destroyed when <code>Button1Click</code> exits.</p>
<p>In the second code sample, the static <code>TRegEx.Match</code> call creates a local variable of type <code>TRegEx</code>.  This local variable goes out of scope when <code>TRegEx.Match</code> returns.  Thus the reference count on the interface reaches zero and <code>TPerlRegEx</code> is destroyed when <code>TRegEx.Match</code> returns.  When we call <code>MatchAgain</code> the <code>TMatch</code> record tries to use a <code>TPerlRegEx</code> instance that has already been destroyed.</p>
<p>To fix this bug, delete or rename the two RegularExpressions.dcu files and copy RegularExpressions.pas into your source code folder.  Make these changes to both the <code>TMatch</code> and <code>TGroupCollection</code> records in this unit:</p>
<ol>
<li>Declare <code>FNotifier: IInterface;</code> in the <code>private</code> section.
</li>
<li>Add the parameter <code>ANotifier: IInterface;</code> to the <code>Create</code> constructor.
</li>
<li>Assign <code>FNotifier := ANotifier;</code> in the constructor&#8217;s implementation.
</li>
</ol>
<p>You also need to add the <code>ANotifier: IInterface;</code> parameter to the <code>TMatchCollection.Create</code> constructor.</p>
<p>Now try to compile some code that uses the <code>RegularExpressions</code> unit.  The compiler will flag all calls to <code>TMatch.Create</code>, <code>TGroupCollection.Create</code> and <code>TMatchCollection.Create</code>.  Fix them by adding the <code>ANotifier</code> or <code>FNotifier</code> parameter, depending on whether <code>ARegEx</code> or <code>FRegEx</code> is being passed.</p>
<p>With these fixes, the <code>TPerlRegEx</code> instance won&#8217;t be destroyed until the last <code>TRegEx</code>, <code>TMatch</code>, or <code>TGroupCollection</code> that uses it goes out of scope or is used with a different regular expression.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.regexguru.com/2010/09/bug-in-delphi-xe-regularexpressions-unit/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

