Skip to main content
Ben Nadel at cf.Objective() 2014 (Bloomington, MN) with: Josh Siok and Megan Siok
Ben Nadel at cf.Objective() 2014 (Bloomington, MN) with: Josh Siok ( @siok ) Megan Siok

June 1st 2008 - National Regular Expression Day! (Post A Comment, Win A Prize)

By on

NOTE: To win prizes, you must post a comment below (and mention which prize you would be interested in).

Not so long ago, I was walking down 14th street in New York City when out of no where, I started to think about Regular Expressions. They are just so awesome. I actually took a moment out of my walk home to stop and think about how much they have made my life better. That might seem like a silly notion to those who have not yet used regular expressions, but I think, to those of you who have used them, this feeling might not be so foreign. Everyday might be a bit of a stretch, but I certainly use regular expression every single week in my work; and, I'm finding new ways to leverage regular expressions all the time.

Regular Expressions are so awesome that I wanted to find a way to really give them their moment in the sun. And so, I am hereby announcing the first ever National Regular Expression Day on Sunday, June 1st, 2008. I'd like this to be a day where people take some time to reflect on how useful regular expressions are. And, if you haven't yet used regular expressions, this would be a great day to maybe set aside some time and finally see what all the hubbub is about.


 
 
 

 
National Regular Expression Day - June 1st, 2008 - Brought To You By Ben Nadel & Kinky Solutions  
 
 
 

And, what national holiday would be complete without some cool prizes and give-aways? To be honest, originally, I wanted to do something cool where people got to flex their Regular Expression muscles, but I have been way too busy lately to really devote a lot of brain power to that. So, as an easy way to enter the give aways, all you have to do is post a comment below (before June 2nd) on how much you like regular expressions and what prize you would be interested in winning. Winners will be selected Monday, June 2nd, 2008. And, what can you win, you ask? Some of the following regular expression related goodies:

1) Shakespeare RegEx Shirt


 
 
 

 
National Regular Expression Day - 2008 - Shakespeare TShirt  
 
 
 

2) xkcd RegEx Shirt


 
 
 

 
National Regular Expression Day - 2008 - XKCD TShirt  
 
 
 

3) RegexBuddy License


 
 
 

 
National Regular Expression Day - 2008 - RegexBuddy License  
 
 
 

4) Mastering Regular Expressions


 
 
 

 
National Regular Expression Day - 2008 - Mastering Regular Expressions  
 
 
 

5) Sams Teach Yourself Regular Expressions in 10 Minutes


 
 
 

 
National Regular Expression Day - 2008 - Sams Teach Yourself Regular Expressions In 10 Minutes  
 
 
 

Good luck, and I hope this is fun for people. And remember, win or lose, if you use Regular Expressions, you are always a winner :)

Reader Comments

111 Comments

That XKCD shirt is great! I began writing my own regular expressions at my blog, as I kept finding them useful, and forgot to add snippets in Eclipse for them. Certainly an easier way to keep track of them. I have (slight) programmer's OCD, and like my code a certain way, so I ended up writing my own CF page that goes through my old CF code (that was not formatted correctly) and rewrites it with corrected spacing and upper/lowercasing, using RegEx to make all of the find/replaces. Certainly much easier than going through by hand and doing it (my OCD isn't *that* bad :) )

41 Comments

The book "Mastering Regular Expressions" by Jeffrey Friedl is the book which I would choose if I could keep only one.

I wrote a review of it on my blog, but I feel like I try to plug myself too often here, so I won't link it - though it shouldn't be too hard to find if you follow the link on my name =).

41 Comments

Also, that shirt is cute, but it's always bothered me as it reads "2 B's or Not B twice" - Argh, urge to regex rising!

This is better:
/(?=bb)|(?!bb)/

Or if it needs to consume/capture (since (?=...) and (?!...) are non-consuming look-aheads):
/(?:(?=bb)|(?!bb))(..)/

PLUS! maybe it should end in /i so that it's case insensitive!

Sed/vi:
s/(?:(?=bb)|(?!bb))(..)/The question is \1/ig

Aah, there, nerdiness satisfied.

1 Comments

I thought I was odd organising an National (now international) Shed week, but without Regular Expression my CF shed site could not run.

41 Comments

@Dan:

I don't think it's exactly the Java version, but I think that's probably what it's closest to. In reality it's not very likely you'll stumble upon the differences between them unless you're doing some reasonably advanced stuff anyway.

Most people stick to capture grouping (...), non-capture grouping (?:...), character classes [a-zA-Z0-9], match any character . , previous 0 or 1 times ?, previous 0 or more times *, previous 1 or more times +, and alternation (aka "or") |. These are common to every reasonably major regex system (though LUA doesn't support alternation!!)

25 Comments

man, why'd you have to make it on a sunday? should have gone for monday, june 2nd so we could have had the day off work (i love 3 day weekends).

i'd be proud to wear the shakespeare regex shirt to commemorate next year's (inter)national regular expression day (which falls on a monday! w00t!) :)

218 Comments

"And, what can you wind, you ask?" o_O I can't wind anything, but I can try to win something with regular expression!

psst! Ben! blog typo. :)

81 Comments

At home I keep my copy of the Regular Expression Pocket Reference right next to my copy of Strunk & White's Elements of Style.

Both are essential references books in my life.

32 Comments

I'd take the shirt. I've already got both books and I am happy with Expresso.

I wish more of my colleagues would learn RegEx--it's such a drag when I get excited about a RegEx solution and none of the other's care. . .sniff. . .they probably won't even appreciate the t-shirt.

15,640 Comments

@Steve,

That's a bit beyond my level :) If I had to make an educated guess, are you using a conditional for Me\I and then [Heart] different spellings of regular expressions?

That ?(1) is a conditional right?

172 Comments

@Ben, yes. More specifically, it's what I call a capturing-group-participation-based conditional, which is a bit of a mouthful (and is not official terminology for any particular regex flavor).

For the sake of deriving some kind of meaning, I suggest you read the regex as "If match 'me', match '[heart] regular expressions', then place 'me' and 'regular expressions' in an atomic group; otherwise end the match". It would match a string like "Me♥RegexMeRegex".

7 Comments

Here in Australia we actually get the 2nd of June off (as some unimportant incidental public holiday - unrelated to technical advances anyways), and since we've got this policy of moving our public holidays to the Monday any time one falls on a weekend, it's just like I get a day off in honour of I.R.E.D.

Hooray!

I was going to post for something (in an effort to obtain the sweet XKCD shirt), but honestly Steve's love for regexes in a regex beats anything I could say :-O

I will say this though:
When I first learned to use them, every problem looked like it would have a regex solution (if you have a hammer, everything looks like a nail syndrome).

The difference is (I was using perl at the time), 9/10 times it did have a regex solution. Usually a good one - a lot of my existing code shrunk from lines and lines to a single line.

1 Comments

hello... it's cool stuff...
I wanna books... about regex...
I use it a lot of time... with python...
It made me comfortable...
because I can reduce my codes...

1 Comments

"Some people, when confronted with a problem, think 'I know, I'll use regular expressions.' Now they have two problems."

But really. Gotta love 'em.

1 Comments

I love regex because I have this huge half-page long pattern to match every single TV show I watch in a couple of IRC channels I'm in. Not to mention wherever else I might be using it (i only wish word and some other text editors supported regex find..) on a daily basis. It saves me so much time I'm only too glad to celebrate a regex day.

/me loser?

Anyway, Steve's regex post owned, but I really want that xkcd shirt :( here's to hoping...

1 Comments

I don't know how anybody develops code without using the regex powers of sed and grep. That's why I'd love to have the book, Mastering Regular Expressions!

1 Comments

that coffee mug is sweet, I have mastering regular expressions and the pocket reference. They are both really good. I also second taking that monday off in observance of the sunday holiday.

1 Comments

Friedls Regular Expression(2nd edition, in German) lies on my desk.
At university, as we had to write a program to query a website and print an result from the site, i used regular expression. My program was the shortest. The lecturer liked it :)
It happened me also that i said at work to a co-worker, "I can do this in regular expression, let me do it".

I would like to get the xkcd shirt.

1 Comments

Awesome idea! Regular expressions deserve more love than they're given.

If chosen, I'd love to win a copy of O'Reilly's Mastering Regular Expressions".

8 Comments

That xkcd t-shirt is cool. :)

Input: International Regular Expression Day

/^\w+(\w)\w{4}(\s)(\w{2})(\w)\w+\s(\w{2})\w{6}(\w)\w\s(\w)(\w)\w$/\1\2\8\7\6\3\2\3\4\5!/

:)

8 Comments

Jane:

>> i only wish word and some other text editors supported regex find <<

jEdit has a good search & replace with RegEx find & replace.

www.jedit.org

1 Comments

As I am finally detoxing off of VB and entering the world of "real languages" I guess I would like: "Sams Teach Yourself Regular Expressions in 10 Minutes".

I have dabbled with them in .NET, but I know I'm not utilizing them even remotely to their potential.

122 Comments

This is very timely. I've found myself increasingly using regex lately to elegantly solve problems we're addressing in our Broadchoice Web Platform! Hardly a day goes by now without me concocting a regex to paste into a Trac ticket to show our offshore team how to perform complex matches or replacements on text, especially related to URL patterns. I always used to think regex was a bit of a hammer and that regex fans thought all problems were nails but as I've become more fluent with it, I've seen the light :)

If I win, I'd love the Shakespeare T - that's very cool!

2 Comments

I've been amazed at what you can accomplish with regular expressions to shorten lots of code. I've also been amazed at how complex and cryptic the regex code can get!

One current problem I'm struggling with is how to replace delimiters around text with HTML tags in a ChordPro-formatted string using ColdFusion. e.g. parsing "A[G]mazing [G7]grace, how [C]sweet the [G]sound" looking for the square brackets and replacing them with <span class="chord"> and </span> respectively... So the final string might look like, "A<span class="chord">G</span>mazing <span class="chord">G7</span>grace, how <span class="chord">C</span>sweet the <span class="chord">G</span>sound" Any ideas? Also is there any way to get the chord out and pass it to a transpose function inside the regex?

Shakespeare T all the way!

2 Comments

Forgot to mention that most of the solutions for transforming ChordPro markup to HTML involves creating a two-row table for each row of ChordPro text. I'd really like to figure out how to format it using CSS instead of tables. :-) That's proving to be a little more difficult than I anticipated when I started it. Most of the open-source tools also use tables...

-matt

1 Comments

Regular expressions have become my life force in the last few weeks when I found out my beloved ereg in PHP is being phazed out. Far more portable and fast it makes my life that much better!

1 Comments

I'd love to own the first prize, the Shakespeare TShirt. I've always loved that different kind of art approach (I even loved the Poems in UML things ;))

1 Comments

RegEx: The most powerful thing that none of our programmer applicants ever seem to know much about. Sad.

I would love either one of the tshirt (1 or 2)

3 Comments

Yay for RegEx Day!

Regular Expressions are a wonderful way to express your awesomeness. My favorites are the ones that do menial tasks for me, such as reformat text in my editor. I blogged it, even: (http://www.dopefly.com/techblog/entry.cfm?entry=222 and 223).

A couple years ago, I made a little util to rename files based on any regex: (http://www.dopefly.com/techblog/entry.cfm?entry=106).

Also, back in '04, I made the Viagra Expression - a big regex to counter viagra spam. You can test it online here: (http://www.dopefly.com/projects/viagratester.cfm). Always meant to circle back and improve it, but I keep forgetting.

If I win something, I think either T-shirt (L) or the O'Reilly book would be fantastic.

7 Comments

RegEx's rock. Great for validating an entire CSV line at one time baby.

^[Man created beer]

Luv the "Shakespeare RegEx Shirt"

5 Comments

^I am the RegEx Ninja! I love RegEx so much, I already own two of those. {2} of those? I'm not averse to owning {2,}. After all, regular expressions have [class].

3 Comments

I never really appreciated regular expressions until I had to do manual string search and replacement....dear God.

Complicated stuff but powerful and worth-while. It should have a birthday that is celebrated all around the world.

15,640 Comments

@Steve,

I thought maybe he was trying to say that he is "empty"? That's what I got from the non-capturing group :) But, some clarification would help :)

5 Comments

i =~ m/(^)(?:.*)($)/;
is a little nonsensical. In perlish, I think it roughly translates as "I match everything." To be honest, I'm not sure what you get when you combine the binding operator (=~) with the match operator (m//).

15,640 Comments

@Eric,

Ahhh, gotcha. On a side note, I have always loved that phrase, "I am the alpha and the omega." I always thought it was very badass sounding.

172 Comments

@Ben Doom, I'm not a Perl hacker, but I know that adding the "m" in `i =~ m/(^)(?:.*)($)/;` doesn't change anything. Some people have a preference to always use it, or not.

@Eric, the parens and the bit about some adjustments being in the spirit of xkcd/208 threw me off, but "I am the alpha and the omega" was actually my best guess at reading it the way you meant it. :-)

Since I can't help but comment even on joke regexes, I'd recommend something like this to help get the point across:

i =~ /\A.*\z/s

5 Comments

@steven

I meant that you usually use =~ with the replacement operator, so that the result is bound back to the variable. IIRC (it's been a few years)

me =~ r/(ben)?\s*doom/The RegEx Ninja/ig;

Poof! The Ninja appears from nowhere!

1 Comments

I wrote the history of meeting Regex at the first time in my life (on the my web page) and some SQL queries' regexes (these are all in Turkish). And also linked to this web page.

I want "Mastering Regular Expressions" by Jeffrey Friedl if I win =:-)

11 Comments

I love how a colleague will be complaining to me that they have to spend all day making a silly change to hundreds or thousands of files by hand, and I can swoop in and save the day with a quick perl command line. Makes me feel like a hero all the time. :)

I would love either tshirt, or the O'Reilly book.

2 Comments

Regular expressions got me through grad-school!

The xkcd shirt is cool... the O'Reilly book is pretty awesome!

3 Comments

Lol...what got me through some of my projects are regex libraries :P.

On second thought, I'd really like any of those prizes. I'd love the o'reilly book or the 24 hours book but I would love to have any of those :P.

3 Comments

Hooray for RegEx Day!

Tip: If you're a Dreamweaver user and need to build a regular expression, start learning about the Server Behavior Builder. When you create a server behavior, Dreamweaver generates a regular expression to match the code block(s). If you're in a hurry (or especially if you're just learning regular expressions), the regexes Dreamweaver generates can be a good starting point. You'll find the regexes it generates are in your user's Configuration in .edml files (which are XML files).

Hope that helps somebody out there... :-) Happy Regex Day!

1 Comments

// My comment is a bit larger because it has code + comments!
// I like regular expressions because the're so easy to use and let you quickly
// handle an amazing variety of pattern matching tasks with very little code.
// Written by Art Wetzel sometime in 1976 or 77 about when V7 Unix came out.
// Its not the full RegEx syntax we know today and is slower than the usual
// state-machine implementation. But... It is nice and short!
// This worked nicely as the core of my own little versions of ed and vi
// If I win I'd like the med or large xkcd RegEx Shirt!!!!

/*
* Art Wetzel's recursive regular expression matcher returns # chars matched
* the regular expression p in the target string s. The b arg points to the
* beginning of line for '^' matching (its usually a copy of the initial s)
* a return value < 0 means no match. 0 is a successful 0 len match.
*/
rem(p, s, b) char *p, *s, *b; {
int t;
char *pi;
switch(*(pi = p)) {
case 0: return(0);
case '^': return(s == b ? rem(++p, s) : -30000);
case '$': return(*s ? -30000 : 0);
case '[':
t = (*(p+1)=='^' ? (*s ? !cclass(p+2, s) : 0) : cclass(p+1, s));
while(*p++ != ']') ;
goto recurse;
case '.': t = *s; p++;
goto recurse;
case '\\': p++;
default:
t = (*p++ == *s);
recurse: if(*p == 0) return(t?1:-30000);
if(*p != '*') return(t && *s != 0 ? 1+rem(p,s+1) : -30000);
return(t ? maxf(1+rem(pi,s+1),rem(p+1,s)) : (rem(p+1,s)));
}
}

maxf(i, j) { return(i>j ? i : j); }

cclass(p, s) char *p, *s; {
int c;
for(c = *s; *p != ']'; ) {
if(*(p+1) == '-') {
if(c >= *p && c<= *(p+2))
return(1);
p += 3;
} else if(*p++ == c) return(c);
}
return(0);
}

1 Comments

It good to see how many people are starting to realize how cool regexes are. I saw the light after using a regex to replace text in about 40 files in less than a minute

I wouldn't mind the XKCD T-shirt. I already have the other.

9 Comments

@Angela

Any female that likes RegEx's is definitely cool by me ... { :) }

That Dreamweaver trick is a pretty cool way to learn RegEx's ...

Not to steal your thunder or anything ... but, for an easy way to "Cheat" at learning RegEx's ... By understanding the definitions of RegexBuddy's tokens, a nOOb can pick up the different syntax "flavors" of RegEx string manipulation really quick ...

1 Comments

Regexes are so tremendously cool. And so are the t-shirts! I'd really love one of them. Also I would recommend Friedl's book to anyone interested in regexes. One of the best tech books I ever read. Not that I've read that many books, but okay...

3 Comments

To celebrate today's holiday, I've compiled 5 Tips for Working With Regular Expressions. (Tip #1 is the tip I left in the comments here, so you can skip that one...) As not to take up a lot of room here on Ben's blog I've posted the tips on my blog instead.

To see all 5 tips, visit http://www.dwmommy.com/?day=6/1/2008#blog627 or click on my name for this comment.

I hope the tips help and that everyone has a wonderful National Regular Expression Day!

3 Comments

@Edward - Thanks, one of these days I'll have to look at RegexBuddy (too bad it isn't on the Mac though, prefer not to switch back and forth to the Windows side)

@Ben - Thanks for hosting, umm creating.... no, inventing -- oh you know what I mean. :-) I see your comments are using a regex to make links out of URLs provided in the comments. Great use for a regular expression there.

@Everyone... Anyone know some good tools for RegExes on the Mac?

15,640 Comments

@All,

HAPPY REGULAR EXPRESSION DAY!

I really appreciate everyone that came out participated. I am glad to see that so many people are finding regular expressions as awesome and wonderful as I do. I wish I had had more time to make this first day better, but I am sure the participation we have seen so far is only a sign of bigger and better things to come next year.

Thanks to everyone. Will be selecting winners tomorrow. Until, then, enjoy!

15,640 Comments

Congratulations to the National Regular Expression winners below who have been selected at random:

* Sean Corfield
* Andity
* Ryan TJ
* Austin
* Jono

Thank you all for having fun with this and helping to get the first annual Regular Expression Day off the ground! I was really excited to see people expressing a love for the language and really sharing some of the ways it has made their lives easier. I am hope that next year is even more exciting.

I will send each of the winner a follow email to gather the necessary information.

Thanks again everyone!

78 Comments

I'm a big fan of API's that auto-correct for common mistakes. For example, if the API says something like Fusebox or ColdBox about including views, i.e "don't include the .cfm extension", which I've done in a number of places, I would write the code so that if they make a mistake and include it anyway, the API will correct the mistake. So frequently in my code you'll see something like this as a quick method of auto-correcting:

rereplacenocase(path,"(\.cfm)?$",".cfm")

remove it if present, then tack it back on. :P

A lot of my regex work ends up being really small pieces like that, rather than big hairy complicated regexes for things like html scrubbing (which I do with XSLT now).

39 Comments

Ben, I'd recommend a couple of contests with common real world expressions. They should be sent privately (so people can't take someone else's idea posted before them and make it better). Each contest should be scored on accuracy (does it solve the problem correctly), simplicity (how long is the pattern), and readability (how easy is it to read and understand what the pattern does).

For example: Find all valid email addresses in a file. Your test file should not be public, and should include a lot of things which look like an email address but are invalid, as well as email addresses which look invalid but actually are, such as those which contain a ' character, and should also include garbage around the email address that might accidentally get picked up.

Another example: Find all valid URLs in a file. Your test file should include http and non-http protocols, ports, bogus characters in the domain, named anchors, and trailing punctuation which should be detected and not included (that's a real world example from online forums and whatnot - the URL often comes at the end of a sentence and has a . or ? after it). Bonus points if it uses sub-expression matching to separate out the various parts of the URL such as protocol, domain, port, directory, file, arguments, named anchor.

At the end of the contest, when the winners are announced, the community benefits from having strong, extensible expressions which they can use to solve common problems.

15,640 Comments

@Eric,

Good ideas. I like the idea of using patterns to grab parts of a file. I'll take these ideas and see what I can some up with. Time to put the thinking cap on :)

1 Comments

XKCD shirt that is great! I started to write my own regular expressions in my blog, as I have found useful, and forgot to add them to fragments in Eclipse. Surely an easier way to track them. I (light), developer of the OCD, and like my code in a certain way, so it ended up writing my own CF page that goes through my old CF code (which was not the correct format) and rewritten with the corrected spacing and upper / lower case, using Regex to make all the find / replace. Certainly much easier than going through the hand and that is what (my OCD is not * that * bad.

1 Comments

hi A lot of my regex work ends up being really small pieces like that, rather than big hairy complicated regexes for things like html scrubbing (which I do with XSLT now).

1 Comments

This post caught my attention. Great stuff here and i noticed lot of feed backs you have here. Pretty much you have a great idea Great job! Thanks for sharing! :)

383 Comments

I came across this by chance. Great idea! Now, Ben, when are you gonna have a contest where you have your participants come up with a cool sql statement, and the coolest one wins? :-)

And here's an idea for a RegEx T-shirt. :-):

Friends don't let friends code without RegExes

lol

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel