June 1st 2008 - National Regular Expression Day! (Post A Comment, Win A Prize)
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.
|
|
|
||
|
|
|||
|
|
|
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:
|
|
|
||
|
|
|||
|
|
|
|
|
|
||
|
|
|||
|
|
|
|
|
|
||
|
|
|||
|
|
|
4) Mastering Regular Expressions
|
|
|
||
|
|
|||
|
|
|
5) 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
Hey, Ben,
Not to throw a wrench into things, but why not make this...umm...unique holiday an international affair? Isn't RegEx an international language? :)
@Brian,
Cut me some slack - it's the first holiday I have ever created :) But yeah, it can be international.
LOL
Regex rocks!
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 :) )
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 =).
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.
@Eric,
Ha ha ha :) Awesome.
I thought I was odd organising an National (now international) Shed week, but without Regular Expression my CF shed site could not run.
If I were to use Regex Buddy, which variation of Regex would I select for Coldfusion? Does it use the Java version?
@Dan,
I assume it uses the Java set of regular expressions, but I am not 100% sure.
@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!!)
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!) :)
I would not suggest mastering regex to the average person - it's just too much information. Yes, I've read it but I'm far from normal. :)
What I do suggest is RegEx in 10 minutes by Ben Forta (http://www.informit.com/store/product.aspx?isbn=0672325667)
It's a good book and I happen to know the tech editor intimately. He's good. :)
"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. :)
@Michael Dinowitz: Like... how intimate? Does Judith know about this?
@Todd,
Good catch :)
@Michael,
The book has been added to the list. Thanks for the suggestion.
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.
$madness =~ /method/
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.
@David: I hear you! I'm looking at YOU, Brian! =)
> post a comment below [...] on how
> much you like regular expressions
I will express my love in regex.
(?i)(me)?(?(1)\u2665((?:reg(?:ular expressions?|ex(?:p|e[ns])?)))|(?!))(?>\1\2)
@Eric, I've debugged that shirt, too. See: http://blog.stevenlevithan.com/archives/2b-or-not-2b :-)
@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?
@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".
@Steve,
Niiice :)
I dig the regEx. I'd love to win the 2b regex shirt.
-j
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.
Hi!
I love RegEx very much!
This one "Mastering Regular Expressions", please ^_^
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...
"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.
Excellent - that xkcd RegEx Shirt is pretty cool, I'd like that
Thanks for starting this, Ben. I've posted my own regex contest / giveaway at http://blog.stevenlevithan.com/archives/regexday-2008 . Of course, everyone here is welcome to participate there as well.
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...
@Jane, I haven't posted what prize I'm interested in, so I'm not in the running (intentionally).
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!
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.
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.
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".
I forgot to specify what I want.
/Shakespeare RegEx Shirt|Mastering Regular Expressions/
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!/
:)
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
Happy regex day! I'd like xkcd shirt please...
Dude, I so totally love regex. I totally want the Shakespeare Regex. Totally.
I'm just learning the complexities to RegEx and each day find it more useful, very cool for IRED. One O'Reilly book for learning please. Thx.
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.
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!
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!
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
@Matt,
Try:
(?i)(\[[abcdefg]\d?\])
... and replace with:
<span class="chord">\1</span>
Yes, I love regular expressions. They are pretty much the only way to process textual information containing patters easily.
And I want a cool T-shirt! Thanks.
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!
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 ;))
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)
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.
RegEx's rock. Great for validating an entire CSV line at one time baby.
^[Man created beer]
Luv the "Shakespeare RegEx Shirt"
I like the Shakespeare shirt.
^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].
Oh, and to fulfill the requirements, I want to run Hamlet in a shell. Possibly Denmark, the nutshell.
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.
Another one: I am /(^).*($)/
Ack, that looks like a crazy Asian emoticon! Non-capturing sub-grouping is in order!
In the spirit of http://xkcd.com/208/ :
i =~ m/(^)(?:.*)($)/;
I just wish I could master regex.
prize 4.
@Eric, how do you read those? I'm sure I'm missing the joke.
@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 :)
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//).
It's probably pretty obscure. I meant it as "I am the beginning and the end" or "I am the alpha and the omega"
@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.
>> I have always loved that phrase, "I am the alpha and the omega."
Me too - ever since playing against Xan in Unreal Tournament. :)
@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
@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!
@Ben Doom, lolz. :)
(Again, not a Perl hacker, but replacements are done with s/// [s stands for substitution].)
@Steven
You're right, it's s///. I *always* got that wrong, now that I think about it.
All of those prizes are great so feel free to send along any of them.
<Regex3
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 =:-)
05/30/08 09:51:35 xkcd tshirt winner!
^.*?:[0-9]{2}\s\w\s\w\s\w$
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.
Regular expressions got me through grad-school!
Regular expressions got me through grad-school!
The xkcd shirt is cool... the O'Reilly book is pretty awesome!
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.
t-shirt!
The first time I realized that RegEx's were f()cking awesome was when I saw RegExPal and parse URI / SplitURL's from Steve ...
I want the Shakespeare shirt ... please ... now.
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!
// 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);
}
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.
@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 ...
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...
How cool. First there's Talk Like a Pirate Day and now this!
I have to find a way to celebrate this with my family.
((Happy Regex Day To )You\n)\1\2.*!\n\1
:)
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!
@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?
@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!
:) I think i am too late, but I would like to say that this is Ben's cool effort.
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!
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).
Can we have international reg ex day 2009?
I think we've got to keep this thing rolling! :)
I'll help where I can
@Matt,
Heck yeah we can! This year, we gotta come up something cool. A real neat contest. Put your thinking cap on.
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.
@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 :)
Surprised. Thanks to the author for a good product. It is a pleasure to read. I am your constant reader!
I've just learned about Regular Expressions and I'm positively surprised. I'll keep an eye on this one. Thanx
It's that time of the year again:
http://sn.im/regex-day-2009
The 2nd Annual (Inter)?National Regular Expression Day!
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.
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).
USE DISCOUNT code 1now5off, 2now5off on CUMS2CAM.COM
http://www.cums2cam.com/us/biopage/girl/SweetiModel
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! :)
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