I’m currently working on the approval application for the NJ LoCo team, and part of it is giving actual evidence of what we discussed — this includes IRC logs. Unfortunately, I never set up a LoCo bot to log the meetings, so I’m currently going through my bip logs for relevant convos. However, bip keeps very precise information. So, while in your irc client it may look like this:
16:16:22 <gQuigs> hi
16:16:49 <harda> gQuigs: You coming Saturday?
16:17:04 <gQuigs> what time does the fair end?
16:17:10 <harda> 14:00.
16:17:18 <gQuigs> oh
In my bip logs, it looks like this:
19-09-2007 16:16:22 < gQuigs!n=bryan@c-24-0-106-77.hsd1.nj.comcast.net: -hi
19-09-2007 16:16:49 < harda!n=harda@pdpc/supporter/silver/harda: +gQuigs: You coming Saturday?
19-09-2007 16:17:04 < gQuigs!n=bryan@c-24-0-106-77.hsd1.nj.comcast.net: -what time does the fair end?
19-09-2007 16:17:10 < harda!n=harda@pdpc/supporter/silver/harda: +14:00.
19-09-2007 16:17:18 < gQuigs!n=bryan@c-24-0-106-77.hsd1.nj.comcast.net: -oh
Lucky for us, we live in a world of regular expressions. A php script and some regex mojo later:
<?
if(STDIN)
{
while(!feof(STDIN))
{
$line = trim(stream_get_line(STDIN,10240,"\n"));
$line = preg_replace('/\d{2}-\d{2}-\d{4} (\d{2}:\d{2}:\d{2}) (?:<|>)? ([^!:]*)(?:![^:]*)?: (?:-|\+)?/','\1 <\2> ', $line); // normal text
$line = preg_replace('/\d{2}-\d{2}-\d{4} (\d{2}:\d{2}:\d{2}) (?:<|>)? ([^!:]*)(?:![^ ]*)? /','\1 \2 ', $line); //emotes
$line = preg_replace('/\d{2}-\d{2}-\d{4} (\d{2}:\d{2}:\d{2}) (?:-!-)? ([^!:]*)(?:![^ ]*)? /','\1 \2 ', $line); // actions
echo $line."\n";
}
}
?>
And we’re right as rain (results can be seen here). That can probably be condensed some, and you could, of course, do that in whatever language you like. On a side note, you won’t realize how difficult WordPress’s Rich Text Editor can really be, until you have to wrestle it into showing properly indented code. Every time I save this post, WordPress mangles my code again.
JoeTerranova.net Print This Post
Joshua K | 17-Oct-07 at 8:04 pm | Permalink
If you’re using KDE, you can also use kregexpeditor to create and test reguilar expressions. At first glance, I thought that there had to be a better/quicker way of doing what you did without the messy regexp, but after another look, you did a really good job of giving a real life case for using regular expressions. It wasn’t too complicated and it used some similar variations, enough that a person new to regexp should be able to learn from it. thanks