Deep Voodoo
Just come across this on photomatt.net – a function to convert double line breaks to paragraphs, with various other niceties thrown in for good measure. Two thoughts on this: firstly, that is a very handy and shiny function. Secondly, it rather rams home just how crazy and unintelligible regular expressions can end up being, even to the experienced. Hell, even the documentation is confusing. Just take a look at it – sit there, stare, and marvel at its sheer impregnability. I was going to quote a short passage in this post, but it appears the sheer number of back and forward slashes has overwhelmed WordPress.
In fact, the only thing I’ve come across more voodoo-like than regexes is mod_rewrite. Which uses regexes.
Now, if you will excuse me, all this thinking is making my brain overheat…
[…] Categories: Tech Blog, 492 words Friendly URLs Since I’m not adverse to regular expressions, I’ve tidied up the addre […]
Nothing to do with the post, if I’m being quite honest, I don’t understand. ANYWAY… I still don’t have a link in the blogroll. I’m gonna get offended very soon.
Afraid it doesn’t look like I can currently add you without recoding the whole thing – my blogroll gets its updates from http://www.blo.gs, and it seems LiveJournal accounts only support this if you pay for the account. So ‘fraid there’s not much I can do about it…
I dunno — writing regular expressions is usually easy, unless you need lots of conditionals and lookahead/lookbehind. That’s how it seems to me, anyway: it’s voodoo when I have to read them, but when I write one it’s the simplest thing in the world…
Mod-rewrite is like a work of art. You never know how it’s going to turn out until you try it.
I love Dorothea Salo’s Brief Guide to Regular Expressions — a wonderfully clear intro to the topic. I find myself referring to it quite a bit; thankfully, I don’t have to dip into regexps very often!
Thanks for that link, Elaine! That might help me out some time.
Don’t you love it when documentation includes the word “might”?
shudder After having spent the last 2 hours intensively reworking my mod_rewrite rules in WPMU this gives me the shivers, and I didn’t use any complex regex, just the thought of it..
It’s true that regexes can be quite scary to comprehend, but it does make things easier if you use the equivalent of Perl’s
x
flag (eXtended legibility), which allows neat stuff like as much whitespace as you want, and comments, too. If I recall correctly, Python hasre.VERBOSE
to help with that.On further investigation, it appears to simply be
/x
for PHP too.