Regex Day Contest

A few months ago Ben Nadel (a regex fan and prominent ColdFusion blogger) asked me if I was interested in promoting his idea for a "National Regular Expression Day," where he'd give away some shirts and books and basically just have some fun with regex evangelism. Well, Ben finally kicked if off, assigning the honor to June 1st, 2008. Make sure to check out his blog post, because by simply posting a comment noting your preferred item from his list before June 2nd, you're entered to win it.

I'm all for regex evangelism, so I figured I'd get in on the action with my own regex contest where you can win the best commercial regex products I know of, worth up to $150! The rules are a little different here though. For one thing, you've got more time to enter — I'll keep this open until the end of Friday, June 13. Second, this isn't a lottery. The rules are still pretty simple, though.

  • Write (or link to) some kind of creative regex content in a comment on this blog post.
  • It has to be something new, specifically for this contest.
  • Enter by unlucky Friday, June 13.
  • When submitting your entry, make sure to include an email address where I can reach you in the email field (it won't be visible to others, and I'll only use it to contact you about this contest).
  • You can submit multiple entries, but each will be judged on its own and one person cannot win more than one award.
  • I get to be the judge and jury.

As for what kind of content is eligible, well, pretty much anything as long as it's regex related. You can write a regex joke (preferably not ending with the punchline "now they have two problems"), post a regex article somewhere, create a regex comic strip, share your favorite regex you've written, design a regex superhero, create a regex game, tell a story about how regexes saved the day, link to a blog post you've written about Regular Expression Day, or whatever you can come up with. Go nuts.

Here's what the winners can choose from. If you win first or second place but none of the prizes in that tier interest you, you can pick two items from a lower level.

Good luck, and I hope you have fun with this. smile (Once again, make sure to check out Ben's post that started this.)

22 thoughts on “Regex Day Contest”

  1. Very nice, but i’m a linux boy (using kregexpeditor), so i’m not interested in ms-win-centric tools.

    s/(microsoft|windows)(.*)([0-9]*)\$/\3 \$ donation for UNICEF/ig ?

  2. “(preferably not ending with the punchline “now they have two problems”)”

    .. ha ha ha ha, that was too funny πŸ™‚ Ok, I got something kind of interesting I am working on for this.

  3. I wrote something about mutable grammars for Perl 6, where grammars are the “next generation” regexes (more like context-free grammars, actually).

    The article assumes a bit of knowledge about Perl 6 regexes, but most of it should be fairly intuitive to grasp.

    So if that counts as a “regex article”, regard this as my submission.


    /run|crawled|scaled( these city walls){2}/

    /(But I still haven’t found what I’m looking for){2}/

  5. I’ve just added another book to the Third Prize list — the excellent Regular Expressions in 10 Minutes by Ben Forta.

    @Da Scritch, a donation to UNICEF is nice, but I’d rather use this opportunity to support high-quality regex products. If, e.g., you win first prize but have no use for PowerGREP, you can pick any other two items on the list.

    @Ben Nadel, cool … I look forward to checking it out.

    @Garety Arch, take your time. This will be open for just over two weeks. Also, I just edited the rules to note that you can submit multiple entries, though each will be judged on its own and one person cannot win more than one award.

    @Moritz, articles first posted after this contest started are valid entries. I don’t see a date on your article other than 2008. Was it posted today? (Perl 6 regexes/rules are cool stuff.)

    @Patrick McElhaney, cute. πŸ™‚ I like your lookahead derivation.

  6. @Steven I posted it a few days ago as preview for the #perl6 people, and linked to it yesterday. (Obviously it wasn’t explicitly written for the contest).

    Don’t know if that works for you, never mind if it doesn’t.

  7. I created an article on Code Project about a Visual Studio AddIn I wrote that provides a find and replace dialog that uses .NET’s regular expressions, rather than the strange syntax used by the built-in dialog:

    I also wrote a Windows PowerShell script that does syntax highlighting for PowerShell code using regular expressions:

    I use that script for the code samples I put on my blog.

  8. Here’s what I could get done for today:

    It’s not really a feasible idea, the way I have it (and the level to which I could figure some stuff out), but it was fun to put together. It’s basically and XML parser that uses regular expressions to read in parts of an XML document and parse it a piece at a time rather than reading in the whole document and parsing it all in memory.

  9. Here’s my entry:

    var REPEATING    = /([1-9])\1+/g;
    REPEATING.test = function () {
    	var result = RegExp.prototype.test.apply(this, arguments);
    	this.lastIndex = 0;
    	return result;
    var Puzzle = function () {};
    Puzzle.prototype.getCandidates = function (row, col, box) {
    	var candidates = this.rowValues(row).concat(this.colValues(col), this.boxValues(box));
    	return "123456789".replace(
    		new RegExp("[" + candidates.sort().join("").replace(REPEATING, "$1").replace(/\./g, "") + "]", "g")
    	, "");
    Puzzle.prototype.hasDuplicates = function () {
    	var rows, cols, boxes;
    	for (var i = 0; i < 9; i += 1) {
    		rows  = this.rowValues(i).sort().join("");
    		cols  = this.colValues(i).sort().join("");
    		boxes = this.boxValues(i).sort().join("");
    		if (REPEATING.test(rows) || REPEATING.test(cols) || REPEATING.test(boxes)) return true;
    	return false;

    This is some skeleton code from a Sudoku game I’ve been writing. I used a main regex, REPEATING, for two purposes: to detect repeating numbers in a sorted string of numbers (for detecting duplicate numbers in a row, column or box) and to reduce a sorted string of digits for a cell’s “buddies” into a unique set of entered digits.

    The methods rowValues, colValues and boxValues retrieve an array of the values for that respective row, column or box in the puzzle.

    I’ve redefined the “test” method on the REPEATING regex to reset the lastIndex property to 0 every time it’s run, so I can give the regex the global flag and still use it for both cases above.

    My favorite trick in this code is the getCandidates method. I concat arrays for the values of a cell’s row, column and box into one array. Then I sort this array, join it into a string, then use the REPEATING regex to get a unique list of the digits entered for this cell’s buddies. I also replace all “.” characters, which represent empty cells, with the empty string. Then I build a new regex from the list of digits that are in the current cell’s buddy cells. This regex is a character class that matches the digits that have already been entered for a cell’s buddies. For example, if a cell’s buddies contain the digits 1, 3, 4, 7 and 9, then the regex will be /[13479]/g. Then I replace all these characters in the string “123456789”, which are the possible values for a Sudoku cell. This leaves me with a list of numbers that are legal candidates for the cell, which in this case would be “2568”.

  10. It may just my own fascination and wonderment with Regexes that motivates this but I am drawn to and interested in the idea of the superhero. I don’t have the deep knowledge of Regex and its use in the various languages and programs to develop this idea completely. Also I just haven’t had much time to think about it. Here are my initial thoughts though.

    To start our hero, like Superman, is affected by either the colors of the sun or the type of “kryptonite” near him. This is the only way I could think to explain the different “versions” of Regex, including its superpowers, weaknesses, actions, and thoughts.

    As I understand Regexes the hero would be closer to his true self when on/near Perl. The affects of Perl make the hero quick and powerful. His natural abilities are easily used and greatly enhanced.

    When on/near Java our hero has the potential to become schizophrenic. His java.util.regex personality is most common but he has others with various benefits and weaknesses. Although he isn’t at home near/on Java he is certainly powerful.

    PHP is a little differnt. In this case he has a dual personality. The preg personality is most common but also the most powerful and liked. The ereg personality is just odd and has some quirks that it harder for him to work and a little limited in his power.

    Our hero tries to stay away from Javascript/ECMA. When near/on it he has some weaknesses. Most noticeable is he never turns around to *lookbehind* him. Big weakness and some of his arch-enemies love to get him in this situation. He can also be much harder for those around him to understand since he has no comments.

    Personally I think he is really great on/near JGSoft. It is like some mad scientist (named Jan ???) used some nefarious (not in a bad way though) DNA resequencing and manipulation to great a hybrid superhero.

    I will admit this is far from being enough to really put our hero to comic or story but it has been interesting to think about. I really wish I had a name for the hero and clearly defined superpowers. For the latter I will blame my limited understanding of Regex and awe of it. I still feel there is almost nothing it can’t do but it would be no fun to have a superhero who was omnipotent. πŸ™‚

    p.s. I will be real curious to see what others can add to this if so inclined. πŸ˜‰

  11. Thanks everyone for participating and creating great, new regex material! Here are the qualifying entries:

    – Patrick McElhaney put U2’s I Still Haven’t Found What I’m Looking For (an appropriate song, indeed) to regular expression.
    – Micahel wrote a regular expression haiku.
    Jeff Hillman wrote up an article about using his Find and Replace Add-In for Visual Studio 2005.
    Ben Nadel posted hundreds of lines of ColdFusion code for a SAX-style XML parser that uses regular expressions to help tokenize the document. It does this using a Java FileInputStream since ColdFusion doesn’t natively support streaming data access.
    Cory Hudson posted a segment of very clever Sudoku game code in JavaScript. It uses regular expressions to help determine what numbers can appear at a position on a partially-completed Sudoku board.
    – Scott described the makings of a regex superhero, and showed that he knows his way around the regular expression flavor landscape.

    Thanks also to those who mentioned excellent regex content created before this contest started:

    – Moritz Lenz highlighted a very interesting article he wrote on mutable grammars for Perl 6.
    – Paul Irish pointed to RegExr, an ActionScript-based regex tester.
    – Jeff Hillman previously wrote an article on PowerShell syntax highlighting with HTML, complete with full source code.

    Finally, Can Sinan Artuc wrote up a regular expression article on his Turkish blog. I wouldn’t be able to properly evaluate this anyway, but since the pingpack didn’t include an email address, it was not a qualifying entry.

    And the winners are:

    1. Ben Nadel
    2. Scott
    3. Jeff Hillman

    I’ll contact you guys within the next few days for your preferred schwag and the addresses to send them to. Feel free to go ahead and send me this info in the mean time (steves_list {at} hotmail {dot-com}).

    Thanks again to everyone who participated!

  12. @Steve,

    AWESOME! I have been down at CFUNITED (ColdFusion conference) all week and *just* got this email. This is way exciting πŸ™‚ Thanks a lot.

  13. hi Steve,

    am new to regex expressions..i am trying to validate this type of string,

    Hi, [[USER_NAME]]
    You are from [[USER_PLACE]].

    Now this is a valid string, but if it contains incomplete markers like [[USER_NAME] or [USER_PLACE]] . how do catch these?
    how do i validate for this..can u suggest something?

  14. I’m cought with a delema. I need to preload an HTML page before any of it displays. Preferably, I’d like to take users to a splash screen, that completely loads the images and text on the following page. But here’s where it gets tricky- the website contains some flash elements as well, which have thier own preloaders. So I don’t want the flash elements to be preloaded, only images and text; so that when the users arive at the page, all the images appear in sync and the flash preloaders get to do their job.

    Does anyone know of a way to do this?

Leave a Reply

Your email address will not be published. Required fields are marked *