Full Flavour Behaviour!

Regex is romantic
posted Friday January 29th @ 1:27am

So I'm still trying my hand at this Internet dating lark. As everyone who's tried it knows, the hardest part is writing your profile without spinning off into a horrid vortex of self-analytical paranoia about how your witticisms might be misconstrued.

However, the particular site I'm using does have one interesting little puzzle which comprises three boxes which need to be filled in at the top of your profile.

I am , and .

Now most people seem to think up a trio of suitably enigmatic adjectives and slip them in there to make a nice little intro to their window on the dating world. Some make nice little messages; my favourite so far is, "I am something, you know, and it's exciting". But could I go one better, perhaps with some sort of famous quote?

Text files of books are available online and I have a powerful pattern-matching program installed in the form of the regex engine in PHP, so why not just run a few decent size books and see what happens?

First up, the pattern itself. I experimented with the profile form and found it would allow up to 20 characters per box. Other than that, I would allow pretty much anything (up to 20 characters) in each box as long as the commas and words between them were in position. I figured commas and semicolons could be interchangeable for the purposes of this experiment. So the pattern looked like this:

/I am .{1,20}[,;] .{1,20}[;,]? and .{1,20}./
Incidentally, I was stripping out all the newlines etc (some of these text files are pre-wrapped, which is annoying) with ereg_replace and it killed off an entire core of the laptop for about ten minutes at 99% - then I aborted, switched the script to use preg_replace and it blasted through 11MB of text in about ten seconds. Blimey. So that's the last time I use ereg_replace then.

So I suppose you want to see the results, eh? Well, I was most disappointed not to recognise a single line. There was nothing in most of the books I processed, which was a bit of a disappointment. The first result, however, was Dickens with this line from David Copperfield:
I am forgiven, I may wake a child and come to you.
Err.. yes that doesn't actually sound very kosher. Let's try Oliver Twist.
I am but a woman; alone here; and unprotected.
Not much better there. How about Dostoyevsky's Crime and Punishment? Dear Lord, the motherlode!
I am telling, Mr. Captain, and I am not to blame. .
I am a luckless fool, I am unworthy of you and drunk . . .
I am sick of it all, do you hear? and have long been.
I am an honest man, Rodion Romanovitch, and will keep my word.

Heady stuff! A little.. down though. Homer's Odyssey has a curiously representative offering:
I am on the sea, I will bear it and make the best of it.

Finally, Shakespeare, starting with Much Ado About Nothing
I am a gentleman, sir, and my name is Conrade.
Othello
I am for it, lieutenant, and I'll do you justice.

But the overall winner has to be this gem from As You Like It:
I am an ass, I am a woman's man, and besides myself.

Marvellous. Expect literary-minded girls to be swooning shortly.

Comment on this entry

Don't miss..

Other Carl sites

Photo galleries