<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Flagrant Badassery</title>
	
	<link>http://blog.stevenlevithan.com</link>
	<description>A JavaScript and regular expression centric blog</description>
	<lastBuildDate>Mon, 28 May 2012 16:36:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/badassery" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="badassery" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbadassery" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbadassery" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbadassery" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bloglines.com/sub/http://feeds.feedburner.com/badassery" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbadassery" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fbadassery" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbadassery" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><item>
		<title>JavaScript Regex Lookbehind Redux</title>
		<link>http://blog.stevenlevithan.com/archives/javascript-regex-lookbehind</link>
		<comments>http://blog.stevenlevithan.com/archives/javascript-regex-lookbehind#comments</comments>
		<pubDate>Mon, 16 Apr 2012 02:09:54 +0000</pubDate>
		<dc:creator>Steven Levithan</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[xregexp]]></category>

		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=608</guid>
		<description><![CDATA[Five years ago I posted Mimicking Lookbehind in JavaScript on this blog, wherein I detailed several ways to emulate positive and negative lookbehind in JavaScript. My approaches back then were all fairly rough, and it was complicated to properly customize any of them to work with a given pattern. Plus, they were only designed to [...]]]></description>
			<content:encoded><![CDATA[<p>Five years ago I posted <em><a href="http://blog.stevenlevithan.com/archives/mimic-lookbehind-javascript">Mimicking Lookbehind in JavaScript</a></em> on this blog, wherein I detailed several ways to emulate positive and negative lookbehind in JavaScript. My approaches back then were all fairly rough, and it was complicated to properly customize any of them to work with a given pattern. Plus, they were only designed to simulate lookbehind in a regex-based replacement.</p>

<p>To make it much easier to use lookbehind, I recently posted a <a href="https://gist.github.com/2387872">collection of short functions</a> on GitHub. They use <a href="http://git.io/xregexp">XRegExp v2</a>, so you should check that out, too.</p>

<p>Here's the code:</p>

<pre class="code fixedHeight"><span class="comment">// Simulating infinite-length leading lookbehind in JavaScript. Uses XRegExp.
// Captures within lookbehind are not included in match results. Lazy
// repetition in lookbehind may lead to unexpected results.</span>

(function (XRegExp) {

    function prepareLb(lb) {
        <span class="comment">// Allow mode modifier before lookbehind</span>
        var parts = /^((?:\(\?[\w$]+\))?)\(\?&lt;([=!])([\s\S]*)\)$/.exec(lb);
        return {
            <span class="comment">// $(?!\s) allows use of (?m) in lookbehind</span>
            lb: XRegExp(parts ? parts[1] + "(?:" + parts[3] + ")$(?!\\s)" : lb),
            <span class="comment">// Positive or negative lookbehind. Use positive if no lookbehind group</span>
            type: parts ? parts[2] === "=" : !parts
        };
    }

    XRegExp.execLb = function (str, lb, regex) {
        var pos = 0, match, leftContext;
        lb = prepareLb(lb);
        while (match = XRegExp.exec(str, regex, pos)) {
            leftContext = str.slice(0, match.index);
            if (lb.type === lb.lb.test(leftContext)) {
                return match;
            }
            pos = match.index + 1;
        }
        return null;
    };

    XRegExp.testLb = function (str, lb, regex) {
        return !!XRegExp.execLb(str, lb, regex);
    };

    XRegExp.searchLb = function (str, lb, regex) {
        var match = XRegExp.execLb(str, lb, regex);
        return match ? match.index : -1;
    };

    XRegExp.matchAllLb = function (str, lb, regex) {
        var matches = [], pos = 0, match, leftContext;
        lb = prepareLb(lb);
        while (match = XRegExp.exec(str, regex, pos)) {
            leftContext = str.slice(0, match.index);
            if (lb.type === lb.lb.test(leftContext)) {
                matches.push(match[0]);
                pos = match.index + (match[0].length || 1);
            } else {
                pos = match.index + 1;
            }
        }
        return matches;
    };

    XRegExp.replaceLb = function (str, lb, regex, replacement) {
        var output = "", pos = 0, lastEnd = 0, match, leftContext;
        lb = prepareLb(lb);
        while (match = XRegExp.exec(str, regex, pos)) {
            leftContext = str.slice(0, match.index);
            if (lb.type === lb.lb.test(leftContext)) {
                <span class="comment">// Doesn't work correctly if lookahead in regex looks outside of the match</span>
                output += str.slice(lastEnd, match.index) + XRegExp.replace(match[0], regex, replacement);
                lastEnd = match.index + match[0].length;
                if (!regex.global) {
                    break;
                }
                pos = match.index + (match[0].length || 1);
            } else {
                pos = match.index + 1;
            }
        }
        return output + str.slice(lastEnd);
    };

}(XRegExp));
</pre>

<p>That's less than 0.5 KB after minification and gzipping. It provides a collection of functions that make it simple to emulate leading lookbehind:</p>

<ul>
<li><code>XRegExp.execLb</code></li>
<li><code>XRegExp.testLb</code></li>
<li><code>XRegExp.searchLb</code></li>
<li><code>XRegExp.matchAllLb</code></li>
<li><code>XRegExp.replaceLb</code></li>
</ul>

<p>Each of these functions takes three arguments: the string to search, the lookbehind pattern as a string (can use XRegExp syntax extensions), and the main regex. <code>XRegExp.replaceLb</code> takes a fourth argument for the replacement value, which can be a string or function.</p>

<p>Usage examples follow:</p>

<pre class="code">XRegExp.execLb("Fluffy cat", "(?i)(?&lt;=fluffy\\W+)", XRegExp("(?i)(?&lt;first&gt;c)at"));
<span class="comment">// -&gt; ["cat", "c"]
// Result has named backref: result.first -&gt; "c"</span>

XRegExp.execLb("Fluffy cat", "(?i)(?&lt;!fluffy\\W+)", /cat/i);
<span class="comment">// -&gt; null</span>

XRegExp.testLb("Fluffy cat", "(?i)(?&lt;=fluffy\\W+)", /cat/i);
<span class="comment">// -&gt; true</span>

XRegExp.testLb("Fluffy cat", "(?i)(?&lt;!fluffy\\W+)", /cat/i);
<span class="comment">// -&gt; false</span>

XRegExp.searchLb("Catwoman's fluffy cat", "(?i)(?&lt;=fluffy\\W+)", /cat/i);
<span class="comment">// -&gt; 18</span>

XRegExp.searchLb("Catwoman's fluffy cat", "(?i)(?&lt;!fluffy\\W+)", /cat/i);
<span class="comment">// -&gt; 0</span>

XRegExp.matchAllLb("Catwoman's cats are fluffy cats", "(?i)(?&lt;=fluffy\\W+)", /cat\w*/i);
<span class="comment">// -&gt; ["cats"]</span>

XRegExp.matchAllLb("Catwoman's cats are fluffy cats", "(?i)(?&lt;!fluffy\\W+)", /cat\w*/i);
<span class="comment">// -&gt; ["Catwoman", "cats"]</span>

XRegExp.replaceLb("Catwoman's fluffy cat is a cat", "(?i)(?&lt;=fluffy\\W+)", /cat/ig, "dog");
<span class="comment">// -&gt; "Catwoman's fluffy dog is a cat"</span>

XRegExp.replaceLb("Catwoman's fluffy cat is a cat", "(?i)(?&lt;!fluffy\\W+)", /cat/ig, "dog");
<span class="comment">// -&gt; "dogwoman's fluffy cat is a dog"</span>

XRegExp.replaceLb("Catwoman's fluffy cat is a cat", "(?i)(?&lt;!fluffy\\W+)", /cat/ig, function ($0) {
    var first = $0.charAt(0);
    return first === first.toUpperCase() ? "Dog" : "dog";
});
<span class="comment">// -&gt; "Dogwoman's fluffy cat is a dog"</span>
</pre>

<p>Easy peasy lemon squeezy. <img src='http://blog.stevenlevithan.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p><img src="http://feeds.feedburner.com/~r/badassery/~4/VoQdj0KtY2A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevenlevithan.com/archives/javascript-regex-lookbehind/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating Grammatical Regexes Using XRegExp.build</title>
		<link>http://blog.stevenlevithan.com/archives/grammatical-patterns-xregexp-build</link>
		<comments>http://blog.stevenlevithan.com/archives/grammatical-patterns-xregexp-build#comments</comments>
		<pubDate>Wed, 04 Apr 2012 17:00:46 +0000</pubDate>
		<dc:creator>Steven Levithan</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[xregexp]]></category>

		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=537</guid>
		<description><![CDATA[Recently, I've added three new addons for XRegExp v2.0 (currently in release candidate stage on GitHub): XRegExp.build &#8212; Lets you build regexes using named subpatterns. Inspired by Lea Verou's RegExp.create. XRegExp Prototype Methods &#8212; Adds a collection of methods to be inherited by XRegExp regexes: apply, call, forEach, globalize, xexec, and xtest. These also work [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I've added three new addons for <a href="http://xregexp.com">XRegExp</a> v2.0 (currently in release candidate stage on <a href="http://git.io/xregexp">GitHub</a>):</p>

<ul>
  <li><strong>XRegExp.build</strong> &mdash; Lets you build regexes using named subpatterns. Inspired by <a href="http://lea.verou.me/">Lea Verou</a>'s <a href="http://lea.verou.me/2011/03/create-complex-regexps-more-easily/">RegExp.create</a>.</li>
  <li><strong>XRegExp Prototype Methods</strong> &mdash; Adds a collection of methods to be inherited by XRegExp regexes: <code>apply</code>, <code>call</code>, <code>forEach</code>, <code>globalize</code>, <code>xexec</code>, and <code>xtest</code>. These also work for native RegExps copied by XRegExp.</li>
  <li><strong>XRegExp Unicode Properties</strong> &mdash; Includes the remaining nine properties (beyond what's already available in other XRegExp addons) required for Level-1 Unicode support: <code>Alphabetic</code>, <code>Uppercase</code>, <code>Lowercase</code>, <code>White_Space</code>, <code>Noncharacter_Code_Point</code>, <code>Default_Ignorable_Code_Point</code>, <code>Any</code>, <code>ASCII</code>, and <code>Assigned</code>.</li>
</ul>

<p>Jumping right into some code, the following demonstrates how the new XRegExp.build addon can be used to create a grammatical pattern for matching real numbers:</p>

<pre class="code"><span class="comment">// Approach 1: Make all of the subpatterns reusable</span>

var lib = {
    digit:             /[0-9]/,
    exponentIndicator: /[Ee]/,
    digitSeparator:    /[_,]/,
    sign:              /[+-]/,
    point:             /[.]/
};
lib.preexponent = XRegExp.build(<span style="color:#33F">'(?xn)\
    {{sign}} ?              \
    (?= {{digit}}           \
      | {{point}}           \
    )                       \
    ( {{digit}} {1,3}       \
      ( {{digitSeparator}} ?\
        {{digit}} {3}       \
      ) *                   \
    ) ?                     \
    ( {{point}}             \
      {{digit}} +           \
    ) ?                     '</span>,
    lib
);
lib.exponent = XRegExp.build(<span style="color:#33F">'(?x)\
    {{exponentIndicator}}\
    {{sign}} ?           \
    {{digit}} +          '</span>,
    lib
);
lib.real = XRegExp.build(<span style="color:#33F">'(?x)\
    ^              \
    {{preexponent}}\
    {{exponent}} ? \
    $              '</span>,
    lib
);

<span class="comment">// Approach 2: No need to reuse the subpatterns. {{sign}} and {{digit}} are
// defined twice, but that can be avoided by defining them before constructing
// the main pattern (see Approach 1).</span>

var real = XRegExp.build(<span style="color:#33F">'(?x)\
    ^              \
    {{preexponent}}\
    {{exponent}} ? \
    $              '</span>,
    {
        preexponent: XRegExp.build(<span style="color:#33F">'(?xn)\
            {{sign}} ?              \
            (?= {{digit}}           \
              | {{point}}           \
            )                       \
            ( {{digit}} {1,3}       \
              ( {{digitSeparator}} ?\
                {{digit}} {3}       \
              ) *                   \
            ) ?                     \
            ( {{point}}             \
              {{digit}} +           \
            ) ?                     '</span>,
            {
                sign:           /[+-]/,
                digit:          /[0-9]/,
                digitSeparator: /[_,]/,
                point:          /[.]/
            }
        ),
        exponent: XRegExp.build(<span style="color:#33F">'(?x)\
            {{exponentIndicator}}\
            {{sign}} ?           \
            {{digit}} +          '</span>,
            {
                sign:              /[+-]/,
                digit:             /[0-9]/,
                exponentIndicator: /[Ee]/
            }
        )
    }
);
</pre>

<p>The <code>real</code> and <code>lib.real</code> regexes created by the above code are identical. Here are a few examples of strings they match:</p>

<ul>
	<li><code>-1</code></li>
	<li><code>1,000</code></li>
	<li><code>10_000_000</code></li>
	<li><code>1,111.1111</code></li>
	<li><code>01.0</code></li>
	<li><code>.1</code></li>
	<li><code>1e2</code></li>
	<li><code>+1.1e-2</code></li>
</ul>

<p>And here are a few examples of strings they don't match:</p>

<ul>
	<li><code>,100</code></li>
	<li><code>10,00</code></li>
	<li><code>1,0000</code></li>
	<li><code>1.</code></li>
	<li><code>1.1,111</code></li>
	<li><code>1k</code></li>
</ul>

<p>Grammatical patterns like this are easier to read, write, and maintain, and look more like a <a href="http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form">BNF</a> than the typical line-noisy regular expressions that some people have come to hate.</p>

<p>Note that the <code>{{&hellip;}}</code> syntax shown here works only for regexes created by <code>XRegExp.build</code>. Named subpatterns can be provided as strings or regex objects (strings are passed to the <code>XRegExp</code> constructor). The provided patterns are automatically wrapped in <nobr><code>(?:&hellip;)</code></nobr> so they can be quantified as a unit and don't interfere with the surrounding pattern in unexpected ways. A leading <code>^</code> and trailing unescaped <code>$</code> are stripped from subpatterns if both are present, which allows embedding independently useful anchored patterns. Flags can be provided via <code>XRegExp.build</code>'s optional third (<code>flags</code>) argument. Native flags used by provided subpatterns are ignored in favor of the <code>flags</code> argument. Backreferences in the outer pattern and provided subpatterns are automatically renumbered to work correctly within the larger combined pattern. The syntax <code>({{<em>name</em>}})</code> works as shorthand for named capture via <code>(?&lt;<em>name</em>&gt;{{<em>name</em>}})</code>. The <code>{{&hellip;}}</code> syntax can be escaped with a backslash.</p>

<p>Play around with the above details a bit, and I think you'll find that XRegExp.build works intuitively and handles any edge cases you throw at it.</p>

<p>Feel free to share how you might alter the above regexes. And make sure to check out the fancy new <a href="http://git.io/xregexp">XRegExp v2.0 and its upgraded addons at GitHub</a>.</p><img src="http://feeds.feedburner.com/~r/badassery/~4/BNtqdC-v0Wo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevenlevithan.com/archives/grammatical-patterns-xregexp-build/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ideas for Regular Expressions Cookbook Second Edition</title>
		<link>http://blog.stevenlevithan.com/archives/regex-cookbook-2-suggestions</link>
		<comments>http://blog.stevenlevithan.com/archives/regex-cookbook-2-suggestions#comments</comments>
		<pubDate>Fri, 02 Mar 2012 10:07:47 +0000</pubDate>
		<dc:creator>Steven Levithan</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=444</guid>
		<description><![CDATA[I'm happy to report that work is underway by Jan Goyvaerts and me on the second edition of Regular Expressions Cookbook. In the new edition, we'll be fixing all known errata, improving existing content, updating everything to support the latest versions of the book's eight covered programming languages, and sprinkling several new recipes into existing [...]]]></description>
			<content:encoded><![CDATA[<p>I'm happy to report that work is underway by <a href="http://www.just-great-software.com/aboutjg.html">Jan Goyvaerts</a> and me on the second edition of <em><a href="http://www.amazon.com/dp/0596520689/?tag=slfb-20">Regular Expressions Cookbook</a></em>. In the new edition, we'll be fixing all known errata, improving existing content, updating everything to support the latest versions of the book's eight covered programming languages, and sprinkling several new recipes into existing chapters.</p>

<p>We'll also be adding a new chapter, tentatively titled "Source Code and Log Files". This new chapter will aim to assist programmers and system admins with common tasks, using regex-based solutions. The recipe list for this chapter remains to be determined, but it will include things like how to find strings and comments in various programming languages, and how to find 404 records within Apache HTTP Server logs.</p>

<p>Do you have an idea for a recipe that you'd like to see added? Suggestions are particularly welcome for this new chapter, but ideas for the rest of the book are also welcome.</p>

<h2>New language editions</h2>

<p>The first edition of <em>Regular Expressions Cookbook</em> has now been published in eight languages. You can get your favorite language version of it from the following sites:</p>

<ul>
	<li><a href="http://www.amazon.com/dp/0596520689/?tag=slfb-20">Regular Expressions Cookbook</a> (English)</li>
	<li><a href="http://www.books.ru/shop/search?query=978-5-93286-181-3">&#x0420;&#x0435;&#x0433;&#x0443;&#x043B;&#x044F;&#x0440;&#x043D;&#x044B;&#x0435; &#x0432;&#x044B;&#x0440;&#x0430;&#x0436;&#x0435;&#x043D;&#x0438;&#x044F; &#x0421;&#x0431;&#x043E;&#x0440;&#x043D;&#x0438;&#x043A; &#x0440;&#x0435;&#x0446;&#x0435;&#x043F;&#x0442;&#x043E;&#x0432;</a> (Russian)</li>
	<li><a href="http://www.amazon.de/dp/3897219573">Regul&#x00E4;re Ausdr&#x00FC;cke Kochbuch</a> (German)</li>
	<li><a href="http://www.amazon.co.jp/gp/product/4873114500/">&#x6B63;&#x898F;&#x8868;&#x73FE;&#x30AF;&#x30C3;&#x30AF;&#x30D6;&#x30C3;&#x30AF;</a> (Japanese)</li>
	<li><a href="http://knihy.cpress.cz/knihy/pocitacova-literatura/programovani/regularni-vyrazy-kucharka-programatora/">Regul&#x00E1;rn&#x00ED; v&#x00FD;razy Kucha&#x0159;ka program&#x00E1;tora</a> (Czech)</li>
	<li><a href="http://www.amazon.cn/gp/product/B003Q97NMU?ver=gp">&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x7ECF;&#x5178;&#x5B9E;&#x4F8B;</a> (Simplified Chinese)</li>
	<li><a href="http://www.hanb.co.kr/book/look.html?isbn=978-89-7914-774-2">&#54620; &#44428;&#51004;&#47196; &#45149;&#45236;&#45716; &#51221;&#44508;&#54364;&#54788;&#49885;</a> (Korean) <strong>NEW</strong></li>
	<li><a href="http://www.novatec.com.br/livros/regexpcookbook/">Express&otilde;es Regulares Cookbook</a> (Brazilian Portuguese) <strong>NEW</strong></li>
</ul><img src="http://feeds.feedburner.com/~r/badassery/~4/F6_Sl8xryQM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevenlevithan.com/archives/regex-cookbook-2-suggestions/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>XRegExp Updates</title>
		<link>http://blog.stevenlevithan.com/archives/xregexp-updates</link>
		<comments>http://blog.stevenlevithan.com/archives/xregexp-updates#comments</comments>
		<pubDate>Sat, 25 Feb 2012 22:55:29 +0000</pubDate>
		<dc:creator>Steven Levithan</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Project Releases]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[Unicode]]></category>
		<category><![CDATA[xregexp]]></category>

		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=466</guid>
		<description><![CDATA[A few days ago, I posted a long-overdue XRegExp bug fix release (version 1.5.1). This was mainly to address an IE issue that a number of people have written to me and blogged about. Specifically, RegExp.prototype.exec no longer throws an error in IE when it is simultaneously provided a nonstring argument and called on a [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, I posted a long-overdue <a href="http://xregexp.com">XRegExp</a> bug fix release (version 1.5.1). This was mainly to address an IE issue that a number of people have written to me and <a href="http://blog.slaks.net/2011/09/xregexp-breaks-jquery-animations.html">blogged about</a>. Specifically, <code>RegExp.prototype.exec</code> no longer throws an error in IE when it is simultaneously provided a nonstring argument and called on a regex with a capturing group that matches an empty string. That's an edge case of an edge case, but it was causing XRegExp to conflict with jQuery 1.7.1 (oops). You can see the full list of changes in the <a href="http://xregexp.com/history/">changelog</a>.</p>

<p>But wait, there's more&hellip; XRegExp's <a href="http://xregexp.com/plugins/#unicode">Unicode plugin</a> has been updated to support Unicode 6.1 (released January 2012), rather than Unicode 5.2. I've also added a new <a href="http://xregexp.com/tests/">test suite</a> with 265 tests so far, and more on the way.</p>

<p>More substantial changes to XRegExp are <a href="https://github.com/slevithan/XRegExp/wiki/Roadmap">planned</a> and coming soon. Follow the brand new <a href="http://git.io/xregexp">XRegExp repository on GitHub</a> to keep up to date or to fork it and help shape the future of this one-of-a-kind JavaScript library. <img src='http://blog.stevenlevithan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p><img src="http://feeds.feedburner.com/~r/badassery/~4/PsGY7_f73t8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevenlevithan.com/archives/xregexp-updates/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regex Syntax Highlighter</title>
		<link>http://blog.stevenlevithan.com/archives/regex-syntax-highlighter</link>
		<comments>http://blog.stevenlevithan.com/archives/regex-syntax-highlighter#comments</comments>
		<pubDate>Mon, 05 Jul 2010 08:55:36 +0000</pubDate>
		<dc:creator>Steven Levithan</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Project Releases]]></category>
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=381</guid>
		<description><![CDATA[Do you regularly post regular expressions online? Have you seen the regex syntax highlighting in RegexPal, RegexBuddy, or on my blog (example), and wanted to apply it to your own websites? Prompted by blog reader Mark McDonnell, I've extracted the regex syntax highlighting engine built into RegexPal and made it into its own library, unimaginatively [...]]]></description>
			<content:encoded><![CDATA[<p>Do you regularly post regular expressions online? Have you seen the regex syntax highlighting in <a href="http://regexpal.com/">RegexPal</a>, <a href="http://www.regexbuddy.com/cgi-bin/affref.pl?aff=SteveL">RegexBuddy</a>, or on my blog (<a href="http://blog.stevenlevithan.com/archives/multi-attr-capture">example</a>), and wanted to apply it to your own websites?</p>

<p>Prompted by blog reader <a href="http://www.integralist.co.uk/">Mark McDonnell</a>, I've extracted the regex syntax highlighting engine built into RegexPal and made it into its own library, unimaginatively named <a href="http://stevenlevithan.com/regex/syntaxhighlighter/"><strong>JavaScript Regex Syntax Highlighter</strong></a>. When combined with the provided CSS, this 1.6 KB self-contained JavaScript file can be used, for instance, to automatically apply regex syntax highlighting to any HTML element with the "<code>regex</code>" class. You can see an example of doing just that on my quick and dirty <a href="http://stevenlevithan.com/regex/syntaxhighlighter/">test page</a>.</p>

<div style="border:1px solid #d3d3d3; background:#f6f6f6; padding:5px; margin:15px 0;">
<p style="text-align:center; margin:0;">Highlighting example:<br />
<code class="regex">&lt;table<b>\b</b><i>[^&gt;]</i><b>*</b>&gt;<b class="g1">(?:</b><b class="g2">(?=</b><b class="g3">(</b><i>[^&lt;]</i><b>+</b><b class="g3">)</b><b class="g2">)</b><b>\1</b><b class="g1">|</b>&lt;<b class="g2">(?!</b>table<b>\b</b><i>[^&gt;]</i><b>*</b>&gt;<b class="g2">)</b><b class="g1">)</b><b class="g1">*?</b>&lt;/table&gt;</code></p>
</div>

<p>Although the library is simple (there's just one function to call), the syntax highlighting is pretty advanced and handles all valid JavaScript regex syntax and errors (with errors highlighted in red). An example of its advanced highlighting support is that it knows, based on the context, whether <code>\10</code> is backreference 10, backreference 1 followed by a literal zero, octal character index 10, or something else altogether due to its position in the surrounding pattern. Speaking of octal escapes (which are de facto browser extensions; not part of the spec.), they are correctly highlighted according to their subtle differences inside and outside character classes (outside of character classes only, octals can include a fourth digit if the leading digit is a zero).</p>

<p>As far as I'm aware, this is the first JavaScript library for highlighting regex syntax, with or without the level of completeness included here. For people who might feel inclined to use or improve upon my work, I've made the licensing as permissive as possible to avoid getting in your way. RegexPal is already open source under the GNU LGPL 3.0 License, but this new library is released under the MIT License. If you plan to customize or help upgrade this code, note that it could probably use a bit of an overhaul (it's ripped from RegexPal with minimal modification), and might <em>require</em> an overhaul if you want to cleanly add support for additional regex flavors. Another nifty feature I plan to eventually add is explanatory <code>title</code> attributes for each element in the returned HTML, which might be particularly helpful for deciphering any highlighted errors or warnings.</p>

<p>Let me know if this library is useful for you, or if there are any other features you'd like to see added or changed. Thanks!</p>

<p>Link: <a href="http://stevenlevithan.com/regex/syntaxhighlighter/"><strong>JavaScript Regex Syntax Highlighter</strong></a>.</p><img src="http://feeds.feedburner.com/~r/badassery/~4/SMQvT9wCNJ0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevenlevithan.com/archives/regex-syntax-highlighter/feed</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>

